[Bf-blender-cvs] [17d96ca] master: GuardedAlloc: safer MEM_SAFE_FREE
Campbell Barton
noreply at git.blender.org
Thu Mar 12 13:49:32 CET 2015
Commit: 17d96ca2aa0429065991fd0812545a4d4746cc86
Author: Campbell Barton
Date: Sat Feb 28 14:41:15 2015 +1100
Branches: master
https://developer.blender.org/rB17d96ca2aa0429065991fd0812545a4d4746cc86
GuardedAlloc: safer MEM_SAFE_FREE
only instantiate the argument once,
so MEM_SAFE_FREE(array[i++]), won't cause incorrect behavior.
===================================================================
M intern/guardedalloc/MEM_guardedalloc.h
===================================================================
diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h
index f0a69f9..05a98c1 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)
More information about the Bf-blender-cvs
mailing list