[Bf-blender-cvs] [6c5f63b] master: Guardedalloc: Add extra logging and checks in MEM_freeN()

Sergey Sharybin noreply at git.blender.org
Wed Feb 18 22:01:07 CET 2015


Commit: 6c5f63b476ccd2ede41b94360641541f0aa9af38
Author: Sergey Sharybin
Date:   Thu Feb 19 01:58:49 2015 +0500
Branches: master
https://developer.blender.org/rB6c5f63b476ccd2ede41b94360641541f0aa9af38

Guardedalloc: Add extra logging and checks in MEM_freeN()

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.

===================================================================

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

===================================================================

diff --git a/intern/guardedalloc/intern/mallocn.c b/intern/guardedalloc/intern/mallocn.c
index a379837..1fd85a0 100644
--- a/intern/guardedalloc/intern/mallocn.c
+++ b/intern/guardedalloc/intern/mallocn.c
@@ -17,6 +17,7 @@
  *
  * Contributor(s): Brecht Van Lommel
  *                 Campbell Barton
+ *                 Sergey Sharybin
  *
  * ***** END GPL LICENSE BLOCK *****
  */
diff --git a/intern/guardedalloc/intern/mallocn_guarded_impl.c b/intern/guardedalloc/intern/mallocn_guarded_impl.c
index ecc5488..9a50342 100644
--- a/intern/guardedalloc/intern/mallocn_guarded_impl.c
+++ b/intern/guardedalloc/intern/mallocn_guarded_impl.c
@@ -22,6 +22,7 @@
  *
  * Contributor(s): Brecht Van Lommel
  *                 Campbell Barton
+ *                 Sergey Sharybin
  *
  * ***** END GPL LICENSE BLOCK *****
  */
diff --git a/intern/guardedalloc/intern/mallocn_lockfree_impl.c b/intern/guardedalloc/intern/mallocn_lockfree_impl.c
index eaa6020..b5f3d1b 100644
--- a/intern/guardedalloc/intern/mallocn_lockfree_impl.c
+++ b/intern/guardedalloc/intern/mallocn_lockfree_impl.c
@@ -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);




More information about the Bf-blender-cvs mailing list