mirror of
https://github.com/DoneJS-Runtime/quickjs-done-nextgen.git
synced 2025-01-09 17:43:15 +00:00
Simplify realloc
Call to our free wrapper when size is 0.
This commit is contained in:
parent
5a41aaa6a3
commit
fb70e0994b
2 changed files with 9 additions and 11 deletions
12
qjs.c
12
qjs.c
|
@ -288,14 +288,14 @@ static void *js_trace_realloc(JSMallocState *s, void *ptr, size_t size)
|
|||
return NULL;
|
||||
return js_trace_malloc(s, size);
|
||||
}
|
||||
old_size = js__malloc_usable_size(ptr);
|
||||
if (size == 0) {
|
||||
js_trace_malloc_printf(s, "R %zd %p\n", size, ptr);
|
||||
s->malloc_count--;
|
||||
s->malloc_size -= old_size + MALLOC_OVERHEAD;
|
||||
free(ptr);
|
||||
|
||||
if (unlikely(size == 0)) {
|
||||
js_trace_free(s, ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
old_size = js__malloc_usable_size(ptr);
|
||||
|
||||
/* When malloc_limit is 0 (unlimited), malloc_limit - 1 will be SIZE_MAX. */
|
||||
if (s->malloc_size + size - old_size > s->malloc_limit - 1)
|
||||
return NULL;
|
||||
|
|
|
@ -1781,13 +1781,11 @@ static void *js_def_realloc(JSMallocState *s, void *ptr, size_t size)
|
|||
return NULL;
|
||||
return js_def_malloc(s, size);
|
||||
}
|
||||
old_size = js__malloc_usable_size(ptr);
|
||||
if (size == 0) {
|
||||
s->malloc_count--;
|
||||
s->malloc_size -= old_size + MALLOC_OVERHEAD;
|
||||
free(ptr);
|
||||
if (unlikely(size == 0)) {
|
||||
js_def_free(s, ptr);
|
||||
return NULL;
|
||||
}
|
||||
old_size = js__malloc_usable_size(ptr);
|
||||
/* When malloc_limit is 0 (unlimited), malloc_limit - 1 will be SIZE_MAX. */
|
||||
if (s->malloc_size + size - old_size > s->malloc_limit - 1)
|
||||
return NULL;
|
||||
|
|
Loading…
Reference in a new issue