From 6e06d6440bc91dff08fdd7f07181468ebb1b39b3 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 9 May 2018 17:40:04 +0000 Subject: fix potential memory leaks * gc.c (rb_alloc_tmp_buffer_with_count): keep the order; allocate an empty imemo first then xmalloc, to get rid of potential memory leak when allocation imemo failed. * parse.y (rb_parser_malloc, rb_parser_calloc, rb_parser_realloc): ditto. * process.c (rb_execarg_allocate_dup2_tmpbuf): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63385 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- process.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'process.c') diff --git a/process.c b/process.c index 5601d82cdc..c1c8432a45 100644 --- a/process.c +++ b/process.c @@ -2358,11 +2358,9 @@ open_func(void *ptr) static void rb_execarg_allocate_dup2_tmpbuf(struct rb_execarg *eargp, long len) { - eargp->dup2_tmpbuf = - rb_imemo_tmpbuf_auto_free_pointer( - ruby_xmalloc( - run_exec_dup2_tmpbuf_size( - len))); + VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer(NULL); + ((rb_imemo_tmpbuf_t *)tmpbuf)->ptr = ruby_xmalloc(run_exec_dup2_tmpbuf_size(len)); + eargp->dup2_tmpbuf = tmpbuf; } static VALUE -- cgit v1.2.3