diff options
author | Peter Zhu <[email protected]> | 2024-01-19 10:26:24 -0500 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2024-01-23 10:47:04 -0500 |
commit | b14674b236445fb70f484603e678722760f678f4 (patch) | |
tree | f3a17922b50abfc863a690e84f0be6dc051305b4 /vm_trace.c | |
parent | 7cf74a2ff28b1b4c26e367d0d67521f7e1fed239 (diff) |
Memory leak with TracePoint on bmethod
[Bug #20194]
When disabling the TracePoint on bmethod, the hooks list is not freed.
For example:
obj = Object.new
obj.define_singleton_method(:foo) {}
bmethod = obj.method(:foo)
tp = TracePoint.new(:return) {}
10.times do
100_000.times do
tp.enable(target: bmethod) {}
end
puts `ps -o rss= -p #{$$}`
end
Before:
18208
22832
26528
29728
34000
37776
40864
44400
47680
51504
After:
16688
17168
17168
17248
17696
17760
17824
17824
17856
17920
Diffstat (limited to 'vm_trace.c')
-rw-r--r-- | vm_trace.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/vm_trace.c b/vm_trace.c index fb896fd423..9d0507879f 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -1259,6 +1259,7 @@ rb_tracepoint_enable_for_target(VALUE tpval, VALUE target, VALUE target_line) (tp->events & (RUBY_EVENT_CALL | RUBY_EVENT_RETURN))) { if (def->body.bmethod.hooks == NULL) { def->body.bmethod.hooks = ZALLOC(rb_hook_list_t); + def->body.bmethod.hooks->is_local = true; } rb_hook_list_connect_tracepoint(target, def->body.bmethod.hooks, tpval, 0); rb_hash_aset(tp->local_target_set, target, Qfalse); |