ruby-changes:55252
From: nobu <ko1@a...>
Date: Sat, 6 Apr 2019 22:21:24 +0900 (JST)
Subject: [ruby-changes:55252] nobu:r67459 (trunk): internal.h: fix potential memory leak
nobu 2019-04-06 22:21:18 +0900 (Sat, 06 Apr 2019) New Revision: 67459 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67459 Log: 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 Modified files: trunk/internal.h Index: internal.h =================================================================== --- internal.h (revision 67458) +++ internal.h (revision 67459) @@ -1132,15 +1132,21 @@ static inline VALUE https://github.com/ruby/ruby/blob/trunk/internal.h#L1132 rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(VALUE str) { const void *src; + VALUE imemo; + rb_imemo_tmpbuf_t *tmpbuf; void *dst; size_t len; 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); src = RSTRING_PTR(str); dst = ruby_xmalloc(len); memcpy(dst, src, len); - return rb_imemo_tmpbuf_auto_free_pointer(dst); + tmpbuf->ptr = dst; + return imemo; } void rb_strterm_mark(VALUE obj); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/