summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-03 07:56:09 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-03 07:56:09 +0000
commitb46b1e3f5a7ec5d72b9597f387e0eee802d4ab63 (patch)
treef7b7d55fdc9bad0993092bbd84f403d7b4cdbde9 /object.c
parent8322ca8a211c48ad1657a041c9f5529baa395762 (diff)
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
Diffstat (limited to 'object.c')
-rw-r--r--object.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/object.c b/object.c
index b994539..44cb842 100644
--- a/object.c
+++ b/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;