ruby-changes:57745
From: Jeremy <ko1@a...>
Date: Sat, 14 Sep 2019 18:26:43 +0900 (JST)
Subject: [ruby-changes:57745] 39c37acf86 (master): Fix memory leak when adding empty keyword hashes
https://git.ruby-lang.org/ruby.git/commit/?id=39c37acf86 From 39c37acf86960ae745c4d690fe2d9dd38cd96fba Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Sat, 14 Sep 2019 02:21:37 -0700 Subject: Fix memory leak when adding empty keyword hashes nagachika pointed out that ALLOC_N is actually just malloc, so this memory wasn't being freed. This shouldn't be a performance sensitive code path, and will be going away after 2.7, so just allocate a temp buffer that will be freed later by Ruby GC. diff --git a/vm_eval.c b/vm_eval.c index f124653..ba57d90 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -241,8 +241,9 @@ add_empty_keyword(int *argc, const VALUE **argv, int *kw_splat) https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L241 if (*kw_splat == RB_PASS_CALLED_KEYWORDS || *kw_splat == RB_PASS_EMPTY_KEYWORDS) { if (*kw_splat == RB_PASS_EMPTY_KEYWORDS || rb_empty_keyword_given_p()) { int n = *argc; - VALUE *ptr = ALLOC_N(VALUE,n+1); - + VALUE v; + VALUE *ptr; + ptr = rb_alloc_tmp_buffer2(&v, n, sizeof(VALUE)); memcpy(ptr, *argv, sizeof(VALUE)*n); ptr[n] = rb_hash_new(); *argc = ++n; -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/