зеркало из https://github.com/github/ruby.git
object.c: fix memory leak
* object.c (rb_obj_copy_ivar): allocate no memory for empty instance variables. [ruby-core:64700] [Bug #10191] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
8322ca8a21
Коммит
b46b1e3f5a
|
@ -1,3 +1,8 @@
|
|||
Wed Sep 3 16:56:07 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* object.c (rb_obj_copy_ivar): allocate no memory for empty
|
||||
instance variables. [ruby-core:64700] [Bug #10191]
|
||||
|
||||
Wed Sep 3 12:05:17 2014 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* process.c (retry_fork_async_signal_safe): Use vfork() if available.
|
||||
|
|
7
object.c
7
object.c
|
@ -270,8 +270,11 @@ rb_obj_copy_ivar(VALUE dest, VALUE obj)
|
|||
}
|
||||
else {
|
||||
long len = ROBJECT(obj)->as.heap.numiv;
|
||||
VALUE *ptr = ALLOC_N(VALUE, len);
|
||||
MEMCPY(ptr, ROBJECT(obj)->as.heap.ivptr, VALUE, len);
|
||||
VALUE *ptr = 0;
|
||||
if (len > 0) {
|
||||
ptr = ALLOC_N(VALUE, len);
|
||||
MEMCPY(ptr, ROBJECT(obj)->as.heap.ivptr, VALUE, len);
|
||||
}
|
||||
ROBJECT(dest)->as.heap.ivptr = ptr;
|
||||
ROBJECT(dest)->as.heap.numiv = len;
|
||||
ROBJECT(dest)->as.heap.iv_index_tbl = ROBJECT(obj)->as.heap.iv_index_tbl;
|
||||
|
|
|
@ -811,4 +811,14 @@ class TestObject < Test::Unit::TestCase
|
|||
assert_raise_with_message(TypeError, "can't convert Array into Integer") {Integer([42])}
|
||||
assert_raise_with_message(TypeError, 'no implicit conversion of Array into Integer') {[].first([42])}
|
||||
end
|
||||
|
||||
def test_copied_ivar_memory_leak
|
||||
bug10191 = '[ruby-core:64700] [Bug #10191]'
|
||||
assert_no_memory_leak([], <<-"end;", <<-"end;", bug10191, rss: true)
|
||||
def (a = Object.new).set; @v = nil; end
|
||||
num = 500_000
|
||||
end;
|
||||
num.times {a.clone.set}
|
||||
end;
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче