Project

General

Profile

Actions

Bug #18553

closed

Memory leak on compiling method call with kwargs

Added by ibylich (Ilya Bylich) about 2 years ago. Updated 7 months ago.

Status:
Closed
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.


Related issues 2 (0 open2 closed)

Related to Ruby master - Bug #19907: Method calls with keyword arguments in eval leaks callcache and callinfo objectsClosedActions
Related to Ruby master - Bug #19906: fix kwarg memory leakClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0