From 03a0ade90d334a616fb5b2d1ed4147a3035ca081 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 17 Jul 2024 15:16:21 +0900 Subject: [PATCH] Fix double free when `getcwd` does not allocate buffer Do not free the result at normal return from `ruby_getcwd`. --- util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util.c b/util.c index 8a18814937..2e887618b1 100644 --- a/util.c +++ b/util.c @@ -564,7 +564,7 @@ ruby_getcwd(void) rb_imemo_tmpbuf_set_ptr(guard, buf); buf = xrealloc(buf, size); } - rb_free_tmp_buffer(&guard); + rb_imemo_tmpbuf_set_ptr(guard, NULL); return buf; }