summaryrefslogtreecommitdiffstats
path: root/stream.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2025-05-31 13:02:35 -0700
committerKaz Kylheku <kaz@kylheku.com>2025-05-31 13:02:35 -0700
commit3ce2f2dcf8b8818926519f5f2652d1f6914eae2c (patch)
treeca6b87b8b35b18c2d5bc1be4e5f717ab97dde2a9 /stream.c
parentb2a3bbde854cb1b46ff84e6cf9f8219c727d42c4 (diff)
downloadtxr-3ce2f2dcf8b8818926519f5f2652d1f6914eae2c.tar.gz
txr-3ce2f2dcf8b8818926519f5f2652d1f6914eae2c.tar.bz2
txr-3ce2f2dcf8b8818926519f5f2652d1f6914eae2c.zip
streams: regression: gc issue in get_string_from_stream.
* stream.c (get_string_from_stream_common): The so->buf = 0 assignment must precede the call to string_own(buf), because the string out stream object may already be garbage, and the string_own call will reclaim it. If we don't null out the buffer, the string will get ownership of a freed buffer. This reproduced in the CSV test case on MacOS Lion, 32 bit x86.
Diffstat (limited to 'stream.c')
-rw-r--r--stream.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/stream.c b/stream.c
index a9f37427..8e4f8ec6 100644
--- a/stream.c
+++ b/stream.c
@@ -2724,8 +2724,8 @@ val get_string_from_stream_common(val stream, val copy_p_in)
if (waste >= 128 && so->size - so->len > so->len / 4)
buf = coerce(wchar_t *, chk_realloc(coerce(mem_t *, so->buf),
(so->len + 1) * sizeof *so->buf));
- out = string_own(buf);
so->buf = 0;
+ out = string_own(buf);
}
return out;