diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/main.c | 4 | ||||
| -rw-r--r-- | src/lib/memory.c | 11 |
2 files changed, 10 insertions, 5 deletions
diff --git a/src/lib/main.c b/src/lib/main.c index d2c353f..1bafa27 100644 --- a/src/lib/main.c +++ b/src/lib/main.c @@ -44,8 +44,10 @@ aplwc_new(struct aplwc_fns fns, enum aplwc_rc *rcp) rc = aplwc_load_module(aplwc, "Boot", (const char *)boot_src, boot_src_len); end: - if(rc != APLWC_OK) + if(rc != APLWC_OK){ aplwc_destroy(aplwc); + aplwc = NULL; + } assert(rcp); *rcp = rc; return aplwc; 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; } } |