Skip to content

Commit

Permalink
Free strdup'ed string space.
Browse files Browse the repository at this point in the history
  • Loading branch information
tadd committed Nov 22, 2024
1 parent 27317bf commit 1b72096
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,25 @@ static void add_to_free_list(void *p)
free_list = ch;
}

static void free_val(Value v)
{
if (value_is_immediate(v) || v == Qnil)
return;
switch (VALUE_TAG(v)) {
case TAG_STR: {
String *p = STRING(v);
free((char *) p->body);
return;
}
case TAG_PAIR:
case TAG_CLOSURE:
case TAG_CONTINUATION:
case TAG_CFUNC:
case TAG_SYNTAX:
return;
}
}

static void sweep(void)
{
static Header dummy = { .size = 0, .allocated = true, .living = false };
Expand All @@ -268,6 +287,7 @@ static void sweep(void)
h->living = false;
prev = h;
} else if (h->allocated) {
free_val((Value)(h+1));
if (!prev->allocated)
prev->size += offset;
else {
Expand Down

0 comments on commit 1b72096

Please sign in to comment.