Guardedalloc: Add extra logging and checks in MEM_freeN()
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 18 Feb 2015 20:58:49 +0000 (01:58 +0500)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 18 Feb 2015 20:58:49 +0000 (01:58 +0500)
We don't like when NULL is send to MEM_freeN(), but there was some
differences between lockfree and guarded allocators:

- Lockfree would have silently crash, in both release and debug modes
- Guarded allocator would have printed error message, abort in debug
  but keep working in release build.

This commit makes lockfree allocator behavior to match guarded one.

intern/guardedalloc/intern/mallocn.c
intern/guardedalloc/intern/mallocn_guarded_impl.c
intern/guardedalloc/intern/mallocn_lockfree_impl.c

index a379837c55290261f74929d72effab512230a20c..1fd85a0c9f58840a3933e26628ac27f0512af94f 100644 (file)
@@ -17,6 +17,7 @@
  *
  * Contributor(s): Brecht Van Lommel
  *                 Campbell Barton
+ *                 Sergey Sharybin
  *
  * ***** END GPL LICENSE BLOCK *****
  */
index ecc54882447dfe82d0bb2898e7a4a2de5025a38a..9a503422282c239105a229c1c29fdc83e09c272e 100644 (file)
@@ -22,6 +22,7 @@
  *
  * Contributor(s): Brecht Van Lommel
  *                 Campbell Barton
+ *                 Sergey Sharybin
  *
  * ***** END GPL LICENSE BLOCK *****
  */
index eaa60202f3c01541f535989b58a29dbb0d0d742b..b5f3d1b15dc73e15b27d59bd650fec815ff123ec 100644 (file)
@@ -134,6 +134,14 @@ void MEM_lockfree_freeN(void *vmemh)
        MemHead *memh = MEMHEAD_FROM_PTR(vmemh);
        size_t len = MEM_lockfree_allocN_len(vmemh);
 
+       if (vmemh == NULL) {
+               print_error("Attempt to free NULL pointer\n");
+#ifdef WITH_ASSERT_ABORT
+               abort();
+#endif
+               return;
+       }
+
        atomic_sub_u(&totblock, 1);
        atomic_sub_z(&mem_in_use, len);