[前][次][番号順一覧][スレッド一覧]

ruby-changes:35773

From: nobu <ko1@a...>
Date: Thu, 9 Oct 2014 13:35:18 +0900 (JST)
Subject: [ruby-changes:35773] nobu:r47855 (trunk): array.c: fix potential memory leak

nobu	2014-10-09 13:35:12 +0900 (Thu, 09 Oct 2014)

  New Revision: 47855

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47855

  Log:
    array.c: fix potential memory leak
    
    * array.c (ary_new): allocate buffer in heap after new object get
      allocated successfully, to get rid of potential memory leak at
      object allocation failure.

  Modified files:
    trunk/array.c
Index: array.c
===================================================================
--- array.c	(revision 47854)
+++ array.c	(revision 47855)
@@ -474,17 +474,14 @@ ary_new(VALUE klass, long capa) https://github.com/ruby/ruby/blob/trunk/array.c#L474
 	RUBY_DTRACE_ARRAY_CREATE(capa, rb_sourcefile(), rb_sourceline());
     }
 
+    ary = ary_alloc(klass);
     if (capa > RARRAY_EMBED_LEN_MAX) {
 	ptr = ALLOC_N(VALUE, capa);
-	ary = ary_alloc(klass);
         FL_UNSET_EMBED(ary);
         ARY_SET_PTR(ary, ptr);
         ARY_SET_CAPA(ary, capa);
         ARY_SET_HEAP_LEN(ary, 0);
     }
-    else {
-	ary = ary_alloc(klass);
-    }
 
     return ary;
 }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]