summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Evans <je@fb.com>2012-02-29 04:24:05 (GMT)
committerJason Evans <je@fb.com>2012-02-29 04:24:05 (GMT)
commitf081b88dfbce94c3c7c8faf0b0f91b117fbdfcc6 (patch)
tree847d6837810b1a44efd75a7378f03bbd823b48aa /src
parentb172610317babc7f365584ddd7fdaf4eb8d9d04c (diff)
downloadjemalloc-f081b88dfbce94c3c7c8faf0b0f91b117fbdfcc6.zip
jemalloc-f081b88dfbce94c3c7c8faf0b0f91b117fbdfcc6.tar.gz
jemalloc-f081b88dfbce94c3c7c8faf0b0f91b117fbdfcc6.tar.bz2
Fix realloc(p, 0) to act like free(p).
Reported by Yoni Londer.
Diffstat (limited to 'src')
-rw-r--r--src/jemalloc.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/jemalloc.c b/src/jemalloc.c
index 08e5f31..865c623 100644
--- a/src/jemalloc.c
+++ b/src/jemalloc.c
@@ -1124,23 +1124,28 @@ JEMALLOC_P(realloc)(void *ptr, size_t size)
;
if (size == 0) {
- if (config_sysv == false || opt_sysv == false)
- size = 1;
- else {
- if (ptr != NULL) {
- if (config_prof || config_stats)
- old_size = isalloc(ptr);
- if (config_prof && opt_prof) {
- old_ctx = prof_ctx_get(ptr);
- cnt = NULL;
- }
- idalloc(ptr);
- } else if (config_prof && opt_prof) {
- old_ctx = NULL;
+ 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) {
+ old_ctx = prof_ctx_get(ptr);
cnt = NULL;
}
+ idalloc(ptr);
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;
+ }
+ ret = NULL;
+ goto RETURN;
+ }
}
}
@@ -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()) {