lua: enforce allocation limit on first alloc

Instead of just on re-alloc.

Ticket: #8507
pull/15328/merge
Jason Ish 3 months ago committed by Victor Julien
parent 24527d662a
commit 2d6c3213ae

@ -64,6 +64,13 @@ static void *LuaAlloc(void *ud, void *ptr, size_t osize, size_t nsize)
return NULL; return NULL;
} else if (ptr == NULL) { } else if (ptr == NULL) {
/* Allocating new data. */ /* Allocating new data. */
if (ctx->alloc_limit != 0 && ctx->alloc_bytes + nsize > ctx->alloc_limit) {
/* This request will exceed the allocation limit. Act as
* though allocation failed. */
ctx->memory_limit_error = true;
return NULL;
}
void *nptr = SCRealloc(ptr, nsize); void *nptr = SCRealloc(ptr, nsize);
if (nptr != NULL) { if (nptr != NULL) {
ctx->alloc_bytes += nsize; ctx->alloc_bytes += nsize;

Loading…
Cancel
Save