Project

General

Profile

Actions

Bug #18553

open

Memory leak on compiling method call with kwargs

Added by ibylich (Ilya Bylich) 5 months ago. Updated 3 months ago.

Status:
Open
Priority:
Normal
Target version:
-
[ruby-core:107302]

Description

The following code produces a memory leak:

p(foo: 1)

It comes from the allocation in compile.c:

struct rb_callinfo_kwarg *kw_arg =
                rb_xmalloc_mul_add(len, sizeof(VALUE), sizeof(struct rb_callinfo_kwarg));

Later it's packed into struct rb_callinfo, but imemo_callinfo is a GC-managed object that has no free calls in obj_free function in gc.c.

I've tried to fix it by calling free on callinfo->kwarg and it fixed leak in ./miniruby -e 'p(foo: 1)', but it breaks make install. My addition causes a double-free error, looks like either callinfo or callinfo->kwarg is shared between multiple objects.
kwarg field is a const pointer, so that's somewhat expected (I was under impression that const qualifier is redundant) :)

I'm pretty sure old versions of Ruby are also affected by this memory leak.

Actions

Also available in: Atom PDF