From 1a6c99600617f069d6d167fb3d33142a07fe0936 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Wed, 22 Apr 2020 20:00:41 -0700 Subject: fix: double free problem --- sys/libbio/test.c | 14 ++++++++------ sys/libn/memory.c | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/sys/libbio/test.c b/sys/libbio/test.c index 3941290..fb79302 100644 --- a/sys/libbio/test.c +++ b/sys/libbio/test.c @@ -36,6 +36,7 @@ static mem·Allocator arena = {.alloc = &bio·alloc, .realloc = &bio·realloc, . // ----------------------------------------------------------------------- // Read/writer +/* Static reader thunk */ static Stream* INPUT; static @@ -52,8 +53,9 @@ unget(byte c) return io·ungetbyte(INPUT, c); } -static io·Peeker peeker = {.get = &get, .unget = &unget}; +static io·Peeker rdr = {.get = &get, .unget = &unget}; +/* Static writer thunk */ static Stream* OUTPUT; static @@ -70,7 +72,7 @@ putstr(string s) return io·putstring(OUTPUT, s); } -static io·Putter putter = {.put = &put, .putstr = &putstr}; +static io·Putter wtr = {.put = &put, .putstr = &putstr}; // ----------------------------------------------------------------------- // Point of entry for testing @@ -96,13 +98,13 @@ main() INPUT = fd[0]; OUTPUT = fd[1]; - printf("starting\n"); - t = bio·readnewick(peeker, arena); - err = bio·writenewick(t, putter); - printf("ending\n"); + t = bio·readnewick(rdr, arena); + err = bio·writenewick(t, wtr); io·flush(fd[1]); io·close(fd[0]); io·close(fd[1]); + + mem·freearena(ARENA); return 0; } diff --git a/sys/libn/memory.c b/sys/libn/memory.c index 6b715d9..ca0c819 100644 --- a/sys/libn/memory.c +++ b/sys/libn/memory.c @@ -102,7 +102,7 @@ grow(mem·Arena *a, vlong min) Assert(a->off == ALIGN_DOWN_PTR(a->off, ARENA_ALIGN)); a->curr->next = blk; - a->curr = blk; + a->curr = blk; } void* @@ -128,11 +128,11 @@ mem·freearena(mem·Arena *a) { struct Block *it, *next; - it = &a->first; + it = a->first.next; while (it != nil) { next = it->next; a->heap.free(it); - it = next; + it = next; } a->heap.free(a); -- cgit v1.2.1