aboutsummaryrefslogtreecommitdiffstats
path: root/cheney_c89.c
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2024-06-12 08:56:49 -0400
committerGravatar Peter McGoron 2024-06-12 08:56:49 -0400
commit26afacd565bff3a016b769cb7ee644b3b75b809d (patch)
treeef65b2ed0bf6dbb77d91307ee7519a9b4b92b58e /cheney_c89.c
parentcheney copying collector (diff)
strings: add more tests
cheney_c89: fix memory leak errors
Diffstat (limited to 'cheney_c89.c')
-rw-r--r--cheney_c89.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/cheney_c89.c b/cheney_c89.c
index bb66973..e6aee3a 100644
--- a/cheney_c89.c
+++ b/cheney_c89.c
@@ -75,7 +75,7 @@ static unsigned char *relocate(struct uns_gc *gc, unsigned char *p)
l = uns_c89_relo_get_len(p);
res = raw_alloc(ctx, l, uns_c89_relo_is_record(p));
memcpy(res, p, l);
- gc->after_collection += l;
+ gc->after_collection += l + sizeof(struct uns_c89_relo_hdr);
uns_c89_relo_set_relo(p, res);
return res;
@@ -90,7 +90,7 @@ static void scan_record(struct uns_gc *gc, unsigned char *p)
for (i = 0; i < l; i++) {
newp = relocate(gc, uns_c89_relo_record_get(p, i));
- memcpy(p, &newp, sizeof(void *));
+ uns_c89_relo_record_set(p, i, newp);
}
}
@@ -130,6 +130,10 @@ int uns_cheney_c89_collect(struct uns_gc *gc)
scanptr = ctx->tospace;
while (scanptr != ctx->tospace_alloc) {
+ /* scanptr currently points to the header data that the mutator
+ * does not usually see.
+ */
+ scanptr += sizeof(struct uns_c89_relo_hdr);
if (uns_c89_relo_is_record(scanptr))
scan_record(gc, scanptr);
scanptr += uns_c89_relo_get_len(scanptr);
@@ -144,10 +148,12 @@ int uns_cheney_c89_collect(struct uns_gc *gc)
static void *alloc(struct uns_gc *gc, size_t bytes, int is_record)
{
struct ctx *ctx = gc->ctx;
+ size_t total_bytes = bytes + sizeof(struct uns_c89_relo_hdr);
- if (ctx->tospace_end - ctx->tospace_alloc < bytes)
+ /* Make sure to check for header space when allocating */
+ if (ctx->tospace_end - ctx->tospace_alloc < total_bytes)
uns_cheney_c89_collect(gc);
- if (ctx->tospace_end - ctx->tospace_alloc < bytes)
+ if (ctx->tospace_end - ctx->tospace_alloc < total_bytes)
gc->oom(gc);
return raw_alloc(ctx, bytes, is_record);