Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-02-28 06:41:15 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-03-12 15:49:15 +0300
commit17d96ca2aa0429065991fd0812545a4d4746cc86 (patch)
tree6d6bad4db0982c6be6d1bed599a875fa7726bddd /intern/guardedalloc/MEM_guardedalloc.h
parent57646cb2ce54ef37e37b61754c29ee658052b8cd (diff)
GuardedAlloc: safer MEM_SAFE_FREE
only instantiate the argument once, so MEM_SAFE_FREE(array[i++]), won't cause incorrect behavior.
Diffstat (limited to 'intern/guardedalloc/MEM_guardedalloc.h')
-rw-r--r--intern/guardedalloc/MEM_guardedalloc.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h
index f0a69f99385..05a98c1a4e5 100644
--- a/intern/guardedalloc/MEM_guardedalloc.h
+++ b/intern/guardedalloc/MEM_guardedalloc.h
@@ -177,7 +177,23 @@ extern "C" {
/** Get the peak memory usage in bytes, including mmap allocations. */
extern size_t (*MEM_get_peak_memory)(void) ATTR_WARN_UNUSED_RESULT;
-#define MEM_SAFE_FREE(v) if (v) { MEM_freeN(v); v = NULL; } (void)0
+#ifdef __GNUC__
+#define MEM_SAFE_FREE(v) do { \
+ typeof(&(v)) _v = &(v); \
+ if (*_v) { \
+ MEM_freeN(*_v); \
+ *_v = NULL; \
+ } \
+} while (0)
+#else
+#define MEM_SAFE_FREE(v) do { \
+ void ** _v = (void **)&(v); \
+ if (*_v) { \
+ MEM_freeN(*_v); \
+ *_v = NULL; \
+ } \
+} while (0)
+#endif
/* overhead for lockfree allocator (use to avoid slop-space) */
#define MEM_SIZE_OVERHEAD sizeof(size_t)