summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-10-05 02:08:07 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-10-05 03:02:09 +0900
commitcbbe198c89fa25a80ec0a5f0592ea00132eacd01 (patch)
tree3913c6ed543ca51f23c1f38a810da647f8c5563d /gc.c
parentc8a18e25c1cc9a44231b97e12f30a98cf9d979bb (diff)
Fix potential memory leaks by `rb_imemo_tmpbuf_auto_free_pointer`
This function has been used wrongly always at first, "allocate a buffer then wrap it with tmpbuf". This order can cause a memory leak, as tmpbuf creation also can raise a NoMemoryError exception. The right order is "create a tmpbuf then allocate&wrap a buffer". So the argument of this function is rather harmful than just useless. TODO: * Rename this function to more proper name, as it is not used "temporary" (function local) purpose. * Allocate and wrap at once safely, like `ALLOCV`.
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c6
1 files changed, 0 insertions, 6 deletions
diff --git a/gc.c b/gc.c
index c9f26cc174..fe01d2b1df 100644
--- a/gc.c
+++ b/gc.c
@@ -2133,12 +2133,6 @@ rb_imemo_tmpbuf_new(VALUE v1, VALUE v2, VALUE v3, VALUE v0)
}
VALUE
-rb_imemo_tmpbuf_auto_free_pointer(void *buf)
-{
- return rb_imemo_new(imemo_tmpbuf, (VALUE)buf, 0, 0, 0);
-}
-
-VALUE
rb_imemo_tmpbuf_auto_free_maybe_mark_buffer(void *buf, size_t cnt)
{
return rb_imemo_tmpbuf_new((VALUE)buf, 0, (VALUE)cnt, 0);