Commit 07b59ee
committed
Fix memory leak when load_from_binary raises
ibf_load_code will leak memory allocated for the code if an exception is
raised. The following script reproduces the leak:
bin = RubyVM::InstructionSequence.of(1.method(:abs)).to_binary
10.times do
100_000.times do
RubyVM::InstructionSequence.load_from_binary(bin)
rescue ArgumentError
end
puts `ps -o rss= -p #{$$}`
end
Before:
18004
23380
28756
34260
39892
45396
50772
55892
61012
66132
After:
12536
12920
13304
13688
14072
14456
14840
15352
15608
158641 parent d0d1246 commit 07b59ee
1 file changed
+3
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12926 | 12926 | | |
12927 | 12927 | | |
12928 | 12928 | | |
| 12929 | + | |
| 12930 | + | |
| 12931 | + | |
12929 | 12932 | | |
12930 | 12933 | | |
12931 | 12934 | | |
| |||
13057 | 13060 | | |
13058 | 13061 | | |
13059 | 13062 | | |
13060 | | - | |
13061 | 13063 | | |
13062 | 13064 | | |
13063 | 13065 | | |
| |||
0 commit comments