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.
This commit is contained in:
Sergey Sharybin 2015-02-19 01:58:49 +05:00
parent 0f2adc0817
commit 6c5f63b476
3 changed files with 10 additions and 0 deletions

View File

@ -17,6 +17,7 @@
*
* Contributor(s): Brecht Van Lommel
* Campbell Barton
* Sergey Sharybin
*
* ***** END GPL LICENSE BLOCK *****
*/

View File

@ -22,6 +22,7 @@
*
* Contributor(s): Brecht Van Lommel
* Campbell Barton
* Sergey Sharybin
*
* ***** END GPL LICENSE BLOCK *****
*/

View 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);