summaryrefslogtreecommitdiff
path: root/src/lib/memory.c
diff options
context:
space:
mode:
authorpeter <peter@pmikkelsen.com>2026-09-04 19:45:05 +0000
committerpeter <peter@pmikkelsen.com>2026-09-04 19:45:05 +0000
commit4d1f519e1bcca659100a2593bd7ca7f2f4983ffe (patch)
treedf2b96f6bb871c8a52c8eda2ac2e2d87387d91bc /src/lib/memory.c
parentcde3778df1f5086052d01bf770910b2e05d0a1e1 (diff)
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
Diffstat (limited to 'src/lib/memory.c')
-rw-r--r--src/lib/memory.c11
1 files changed, 7 insertions, 4 deletions
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;
}
}