summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/gc.c b/gc.c
index 1d7ad561f4..bd52966bf1 100644
--- a/gc.c
+++ b/gc.c
@@ -8141,9 +8141,17 @@ void *
rb_alloc_tmp_buffer_with_count(volatile VALUE *store, size_t size, size_t cnt)
{
void *ptr;
+ VALUE imemo;
+ rb_imemo_tmpbuf_t *tmpbuf;
+ /* Keep the order; allocate an empty imemo first then xmalloc, to
+ * get rid of potential memory leak */
+ imemo = rb_imemo_tmpbuf_auto_free_maybe_mark_buffer(NULL, 0);
+ *store = imemo;
ptr = ruby_xmalloc0(size);
- *store = rb_imemo_tmpbuf_auto_free_maybe_mark_buffer(ptr, cnt);
+ tmpbuf = (rb_imemo_tmpbuf_t *)imemo;
+ tmpbuf->ptr = ptr;
+ tmpbuf->cnt = cnt;
return ptr;
}