diff options
author | Peter Zhu <[email protected]> | 2023-06-29 09:21:11 -0400 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2023-06-29 11:16:50 -0400 |
commit | f0d08d11dcd404f3146c0d71d6ff743bbc6e7193 (patch) | |
tree | 82e6bb0fff741e124915c7a2f6aabe54a484ee71 /include/ruby | |
parent | df2b3a29987e9353596af76ed77f35d7366d654e (diff) |
Fix memory leak when copying ST tables
st_copy allocates a st_table, which is not needed for hashes since it is
allocated by VWA and embedded, so this causes a memory leak.
The following script demonstrates the issue:
```ruby
20.times do
100_000.times do
{a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}
end
puts `ps -o rss= -p #{$$}`
end
```
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/8000
Diffstat (limited to 'include/ruby')
-rw-r--r-- | include/ruby/st.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/include/ruby/st.h b/include/ruby/st.h index 0d42283364..ba69c066c9 100644 --- a/include/ruby/st.h +++ b/include/ruby/st.h @@ -162,6 +162,8 @@ void rb_st_cleanup_safe(st_table *, st_data_t); #define st_cleanup_safe rb_st_cleanup_safe void rb_st_clear(st_table *); #define st_clear rb_st_clear +st_table *rb_st_replace(st_table *new_tab, st_table *old_tab); +#define st_replace rb_st_replace st_table *rb_st_copy(st_table *); #define st_copy rb_st_copy CONSTFUNC(int rb_st_numcmp(st_data_t, st_data_t)); |