From 4d1f519e1bcca659100a2593bd7ca7f2f4983ffe Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 4 Sep 2026 19:45:05 +0000 Subject: Add a test which runs all the scripts in tests/scripts/good to meaure how many memory allocations they perform, and then rerun them with a mode that causes the memory allocator to fail after N allocations. The scripts are run for all values of N from 0 to the number of allocations they need to succeed. FossilOrigin-Name: ed1953c203d3493d9c1adbcb9256d7d380bc1fdcfc7856f03f9d801291f478cd --- src/lib/memory.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/lib/memory.c') diff --git a/src/lib/memory.c b/src/lib/memory.c index b5bb82a..583b2ab 100644 --- a/src/lib/memory.c +++ b/src/lib/memory.c @@ -53,7 +53,7 @@ memory_init(struct aplwc *aplwc) void memory_destroy(struct aplwc *aplwc) { - if(aplwc->fns.dealloc) + if(aplwc->fns.dealloc && aplwc->unaligned_data) aplwc->fns.dealloc(aplwc->unaligned_data); } @@ -173,8 +173,7 @@ grow(struct aplwc *aplwc, size_t extra) if(aplwc->data){ memmove(aligned_data, aplwc->data, aplwc->size); fixrefs(aplwc, aligned_data, aplwc->data); - if(aplwc->fns.dealloc) - aplwc->fns.dealloc(aplwc->unaligned_data); + memory_destroy(aplwc); for(free = head; free; free = next(free)) if(next(free)) assert((free)->tag != CHUNK_TAG_FREE); @@ -380,7 +379,9 @@ alloc(struct aplwc *aplwc, size_t size, enum chunk_tag tag) if(pad) size += ALIGNMENT - pad; - + if(aplwc->fns.hook_alloc && !aplwc->fns.hook_alloc()) + goto fail; + attempt = 0; retry: DEBUG(check_mem(aplwc)); @@ -398,6 +399,8 @@ retry: goto retry; /* fall-through */ default: +fail: + aplwc->last_error = APLWC_OUT_OF_MEMORY; return NULL; } } -- cgit v1.2.3