diff options
| author | Peter Zhu <peter@peterzhu.ca> | 2025-09-19 10:37:40 -0400 |
|---|---|---|
| committer | Peter Zhu <peter@peterzhu.ca> | 2025-09-21 08:24:21 -0400 |
| commit | 3ec597f619a739ef6518c1f0ac3f58a168983730 (patch) | |
| tree | 8eb15a17a2e0aaff532a336d16e7813e81744f44 /include/ruby/ruby.h | |
| parent | 5179b7fb3f9c3a27c69bebcbdba380c0c5f1d42d (diff) | |
Fix memory leak in cloning complex imemo_fields
When we clone a complex imemo_fields, it calls creates the imemo_fields
using rb_imemo_fields_new_complex, which allocates and initializes a new
st_table. However, st_replace will directly replace any exisiting fields
in the st_table, causing it to leak.
For example, this script demonstrates the leak:
obj = Class.new
8.times do |i|
obj.instance_variable_set(:"@test#{i}", nil)
obj.remove_instance_variable(:"@test#{i}")
end
obj.instance_variable_set(:"@test", 1)
10.times do
100_000.times do
obj.dup
end
puts `ps -o rss= -p #{$$}`
end
Before:
26320
39296
52320
63136
75520
87008
97856
114800
120864
133504
After:
16288
20112
20416
20720
20800
20864
21184
21424
21904
21904
Diffstat (limited to 'include/ruby/ruby.h')
0 files changed, 0 insertions, 0 deletions
