зеркало из https://github.com/github/ruby.git
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
This commit is contained in:
Родитель
098b0ba572
Коммит
4adfbab35c
5
array.c
5
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;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче