Fix realloc(p, 0) to act like free(p).

Reported by Yoni Londer.
This commit is contained in:
Jason Evans 2012-02-28 20:24:05 -08:00
parent b172610317
commit f081b88dfb

View File

@ -1124,10 +1124,8 @@ JEMALLOC_P(realloc)(void *ptr, size_t size)
;
if (size == 0) {
if (config_sysv == false || opt_sysv == false)
size = 1;
else {
if (ptr != NULL) {
/* realloc(ptr, 0) is equivalent to free(p). */
if (config_prof || config_stats)
old_size = isalloc(ptr);
if (config_prof && opt_prof) {
@ -1135,7 +1133,13 @@ JEMALLOC_P(realloc)(void *ptr, size_t size)
cnt = NULL;
}
idalloc(ptr);
} else if (config_prof && opt_prof) {
ret = NULL;
goto RETURN;
} else {
if (config_sysv == false || opt_sysv == false)
size = 1;
else {
if (config_prof && opt_prof) {
old_ctx = NULL;
cnt = NULL;
}
@ -1143,6 +1147,7 @@ JEMALLOC_P(realloc)(void *ptr, size_t size)
goto RETURN;
}
}
}
if (ptr != NULL) {
assert(malloc_initialized || malloc_initializer ==
@ -1188,6 +1193,7 @@ OOM:
errno = ENOMEM;
}
} else {
/* realloc(NULL, size) is equivalent to malloc(size). */
if (config_prof && opt_prof)
old_ctx = NULL;
if (malloc_init()) {