mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Use reference counting to avoid memory leak in kwargs
Tracks other callinfo that references the same kwargs and frees them when all references are cleared. [bug #19906] Co-authored-by: Peter Zhu <peter@peterzhu.ca>
This commit is contained in:
parent
be09c8370b
commit
c74dc8b4af
4 changed files with 18 additions and 2 deletions
|
@ -43,6 +43,7 @@ enum vm_call_flag_bits {
|
|||
|
||||
struct rb_callinfo_kwarg {
|
||||
int keyword_len;
|
||||
int references;
|
||||
VALUE keywords[];
|
||||
};
|
||||
|
||||
|
@ -199,6 +200,9 @@ vm_ci_dump(const struct rb_callinfo *ci)
|
|||
static inline const struct rb_callinfo *
|
||||
vm_ci_new_(ID mid, unsigned int flag, unsigned int argc, const struct rb_callinfo_kwarg *kwarg, const char *file, int line)
|
||||
{
|
||||
if (kwarg) {
|
||||
((struct rb_callinfo_kwarg *)kwarg)->references++;
|
||||
}
|
||||
if (USE_EMBED_CI && VM_CI_EMBEDDABLE_P(mid, flag, argc, kwarg)) {
|
||||
RB_DEBUG_COUNTER_INC(ci_packed);
|
||||
return vm_ci_new_id(mid, flag, argc, kwarg);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue