From cc766a2d2cf7348b2b5f7d78ba1bd9005949c8bd Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 26 Mar 2016 12:02:15 +0100 Subject: [PATCH] let xbt_heap_free(NULL) be a noop --- src/surf/cpu_cas01.cpp | 4 +--- src/surf/network_interface.hpp | 3 +-- src/xbt/heap.c | 7 ++++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index fb91f38ab5..0469a17199 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -71,9 +71,7 @@ CpuCas01Model::~CpuCas01Model() { lmm_system_free(maxminSystem_); maxminSystem_ = NULL; - - if (actionHeap_) - xbt_heap_free(actionHeap_); + xbt_heap_free(actionHeap_); delete modifiedSet_; surf_cpu_model_pm = NULL; diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index b5330ad715..8362e85704 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -66,8 +66,7 @@ namespace simgrid { ~NetworkModel() { if (maxminSystem_) lmm_system_free(maxminSystem_); - if (actionHeap_) - xbt_heap_free(actionHeap_); + xbt_heap_free(actionHeap_); delete modifiedSet_; } diff --git a/src/xbt/heap.c b/src/xbt/heap.c index 96da93ec17..5bfca96009 100644 --- a/src/xbt/heap.c +++ b/src/xbt/heap.c @@ -53,13 +53,14 @@ inline void xbt_heap_set_update_callback(xbt_heap_t H, void (*update_callback) ( */ void xbt_heap_free(xbt_heap_t H) { - int i; + if (!H) + return; + if (H->free) - for (i = 0; i < H->count; i++) + for (int i = 0; i < H->count; i++) H->free(H->items[i].content); free(H->items); free(H); - return; } /** -- 2.20.1