internal.h: fix potential memory leak
* internal.h (rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString): create tmpbuf to keep the pointer before xmalloc which can raise a NoMemoryError exception. extracted from https://github.com/bear-metal/ruby/tree/transient-imemo-tmpbuf git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f15d043588
commit
fe979e5bce
@ -1132,15 +1132,21 @@ static inline VALUE
|
|||||||
rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(VALUE str)
|
rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(VALUE str)
|
||||||
{
|
{
|
||||||
const void *src;
|
const void *src;
|
||||||
|
VALUE imemo;
|
||||||
|
rb_imemo_tmpbuf_t *tmpbuf;
|
||||||
void *dst;
|
void *dst;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
SafeStringValue(str);
|
SafeStringValue(str);
|
||||||
|
/* create tmpbuf to keep the pointer before xmalloc */
|
||||||
|
imemo = rb_imemo_tmpbuf_auto_free_pointer(NULL);
|
||||||
|
tmpbuf = (rb_imemo_tmpbuf_t *)imemo;
|
||||||
len = RSTRING_LEN(str);
|
len = RSTRING_LEN(str);
|
||||||
src = RSTRING_PTR(str);
|
src = RSTRING_PTR(str);
|
||||||
dst = ruby_xmalloc(len);
|
dst = ruby_xmalloc(len);
|
||||||
memcpy(dst, src, len);
|
memcpy(dst, src, len);
|
||||||
return rb_imemo_tmpbuf_auto_free_pointer(dst);
|
tmpbuf->ptr = dst;
|
||||||
|
return imemo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rb_strterm_mark(VALUE obj);
|
void rb_strterm_mark(VALUE obj);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user