summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-09 04:35:12 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-09 04:35:12 +0000
commit4adfbab35c128a0c3b9f1fdb7c0d89ccdaf55351 (patch)
tree316f9e788c129811cef5262e1701dc6c9b448cfb /array.c
parent098b0ba572d624acdc2af1925db7feda4b72881e (diff)
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/array.c b/array.c
index 9884092..71e9b46 100644
--- a/array.c
+++ b/array.c
@@ -474,17 +474,14 @@ ary_new(VALUE klass, long capa)
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;
}