fixed realloc(0) may alloc min unit memory on some allocator

This commit is contained in:
Penner 2025-05-06 18:48:14 +08:00
parent a8b2d7c2b2
commit 68acb60984
3 changed files with 9 additions and 1 deletions

View File

@ -2448,7 +2448,7 @@ int lre_exec(uint8_t **capture,
stack_buf = alloca(alloca_size);
ret = lre_exec_backtrack(s, capture, stack_buf, 0, bc_buf + RE_HEADER_LEN,
cbuf + (cindex << cbuf_type), FALSE);
lre_realloc(s->opaque, s->state_stack, 0);
lre_free(s->opaque, s->state_stack);
return ret;
}

View File

@ -56,5 +56,6 @@ int lre_check_stack_overflow(void *opaque, size_t alloca_size);
/* must be provided by the user, return non zero if time out */
int lre_check_timeout(void *opaque);
void *lre_realloc(void *opaque, void *ptr, size_t size);
void lre_free(void *opaque, void *ptr);
#endif /* LIBREGEXP_H */

View File

@ -44594,6 +44594,13 @@ void *lre_realloc(void *opaque, void *ptr, size_t size)
return js_realloc_rt(ctx->rt, ptr, size);
}
void lre_free(void *opaque, void *ptr)
{
JSContext *ctx = opaque;
/* No JS exception is raised here */
js_free_rt(ctx->rt, ptr);
}
static JSValue js_regexp_escape(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv)
{