aboutsummaryrefslogtreecommitdiffstats
path: root/vm_callinfo.h
diff options
context:
space:
mode:
authorHParker <HParker@github.com>2023-09-29 14:06:26 -0700
committerPeter Zhu <peter@peterzhu.ca>2023-10-01 10:55:19 -0400
commitc74dc8b4af4ef1b32f65587f083fbeba4ca186fa (patch)
treeaccaa8ec5d5b0aadb8ee0368530229450c6e8df2 /vm_callinfo.h
parentbe09c8370b8f332620592b1837e040ded583489f (diff)
downloadruby-c74dc8b4af4ef1b32f65587f083fbeba4ca186fa.tar.gz
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>
Diffstat (limited to 'vm_callinfo.h')
-rw-r--r--vm_callinfo.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/vm_callinfo.h b/vm_callinfo.h
index 91c92854d7..fb6998b8b3 100644
--- a/vm_callinfo.h
+++ b/vm_callinfo.h
@@ -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);