diff options
| author | Peter Zhu <peter@peterzhu.ca> | 2024-02-06 10:20:55 -0500 |
|---|---|---|
| committer | Peter Zhu <peter@peterzhu.ca> | 2024-02-07 12:15:33 -0500 |
| commit | b2392c6be418703e8941226ac80b359188bf3c5d (patch) | |
| tree | 5a986a29bb26732572f999c686e67b419f5659c5 /parse.y | |
| parent | f741b05d1f06a1d82e9cc6ccd722a06bb42c3347 (diff) | |
Fix memory leak when parsing invalid pattern matching
If the pattern matching is invalid, then the pvtbl would get leaked. For
example:
10.times do
100_000.times do
eval(<<~RUBY)
case {a: 1}
in {"a" => 1}
end
RUBY
rescue SyntaxError
end
puts `ps -o rss= -p #{$$}`
end
Before:
28096
44768
61472
78512
94992
111504
128096
144528
161008
177472
After:
14096
14112
14112
14176
14208
14240
14240
14240
14240
14240
Diffstat (limited to 'parse.y')
| -rw-r--r-- | parse.y | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -16070,6 +16070,11 @@ rb_ruby_parser_free(void *ptr) } } string_buffer_free(p); + + if (p->pvtbl) { + st_free_table(p->pvtbl); + } + xfree(ptr); } |
