From 657c6fedce9c743e46badcc4457a1fbaa8901d7e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 13 May 2017 19:42:27 -0700 Subject: bugfix: gc-incorrect creation of catenated stream. * stream.c (make_catenated_stream): Fix incorrect order of operations: list of streams stored into a structure that is not yet visible to the garbage collector. (Rules for coding this properly are explained in HACKING.) This was found by running a test with --gc-debug on 64 bit Darwin. The read_eval_stream function calls make_catenated_stream with an argument that is freshly constructed in the argument expression itself, triggering the issue. --- stream.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stream.c b/stream.c index b34da981..398feaf6 100644 --- a/stream.c +++ b/stream.c @@ -2343,9 +2343,12 @@ static struct strm_ops cat_stream_ops = val make_catenated_stream(val stream_list) { struct cat_strm *s = coerce(struct cat_strm *, chk_malloc(sizeof *s)); + val catstrm = nil; strm_base_init(&s->a); + s->streams = nil; + catstrm = cobj(coerce(mem_t *, s), stream_s, &cat_stream_ops.cobj_ops); s->streams = stream_list; - return cobj(coerce(mem_t *, s), stream_s, &cat_stream_ops.cobj_ops); + return catstrm; } val make_catenated_stream_v(struct args *streams) -- cgit v1.2.3