Revert "Avoid NULL check in free() and malloc_usable_size()."
This reverts commit 96d4120ac08db3f2d566e8e5c3bc134a24aa0afc.
ivsalloc() depends on chunks_rtree being initialized. This can be
worked around via a NULL pointer check. However,
thread_allocated_tsd_get() also depends on initialization having
occurred, and there is no way to guard its call in free() that is
cheaper than checking whether ptr is NULL.
diff --git a/src/jemalloc.c b/src/jemalloc.c
index 86ce695..1deabcd 100644
--- a/src/jemalloc.c
+++ b/src/jemalloc.c
@@ -1100,18 +1100,22 @@
void
je_free(void *ptr)
{
- size_t usize;
- assert(malloc_initialized || IS_INITIALIZER);
+ if (ptr != NULL) {
+ size_t usize;
- if (config_prof && opt_prof) {
- usize = isalloc(ptr);
- prof_free(ptr, usize);
- } else if (config_stats)
- usize = isalloc(ptr);
- if (config_stats)
- thread_allocated_tsd_get()->deallocated += usize;
- idalloc(ptr);
+ assert(malloc_initialized || IS_INITIALIZER);
+
+ if (config_prof && opt_prof) {
+ usize = isalloc(ptr);
+ prof_free(ptr, usize);
+ } else if (config_stats) {
+ usize = isalloc(ptr);
+ }
+ if (config_stats)
+ thread_allocated_tsd_get()->deallocated += usize;
+ idalloc(ptr);
+ }
}
/*
@@ -1196,7 +1200,7 @@
if (config_ivsalloc)
ret = ivsalloc(ptr);
else
- ret = isalloc(ptr);
+ ret = (ptr != NULL) ? isalloc(ptr) : 0;
return (ret);
}