diff options
author | Peter Zhu <[email protected]> | 2024-08-09 10:57:01 -0400 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2024-08-12 09:33:20 -0400 |
commit | 568d7ab7f5862063107b3643c6cfe77a387f09d6 (patch) | |
tree | 8cc430d5c41ae9c0682a47538787b7a5a1924b3f | |
parent | 992596fb7af18a7f472589a607d0eb3fbb03b49a (diff) |
Fix memory leak reported in -test-/random/loop.c
RUBY_TYPED_DEFAULT_FREE will only free the rand_loop_t, but it will cause
the buf to be leaked. This commit fixes the memory leak by implementing
a free function for the rand_loop_t type.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11354
-rw-r--r-- | ext/-test-/random/loop.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/ext/-test-/random/loop.c b/ext/-test-/random/loop.c index b789ab1d01..f79e5cfd83 100644 --- a/ext/-test-/random/loop.c +++ b/ext/-test-/random/loop.c @@ -13,6 +13,15 @@ static const rb_random_interface_t random_loop_if = { RB_RANDOM_INTERFACE_DEFINE_WITH_REAL(loop) }; +static void +loop_free(void *ptr) +{ + rand_loop_t *r = ptr; + + xfree(r->buf); + xfree(r); +} + RB_RANDOM_DEFINE_INIT_INT32_FUNC(loop) static size_t random_loop_memsize(const void *ptr) @@ -25,7 +34,7 @@ static rb_random_data_type_t random_loop_type = { "random/loop", { rb_random_mark, - RUBY_TYPED_DEFAULT_FREE, + loop_free, random_loop_memsize, }, RB_RANDOM_PARENT, |