summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-15 15:09:40 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-15 15:09:40 +0000
commit4c17014bf3e49f480a2a5018e9cd4d855bece432 (patch)
treef97f21455f80983b18ad8bb19189cf733a9faa6b /gc.c
parent9ffd060b30b85a1783d6dd81dd41ebf447e9b3e1 (diff)
* gc.c (assign_heap_slot): fix fear of memory leak and memory
violation. Coverity Scan found this bug. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29801 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/gc.c b/gc.c
index b8c8c36684..cf9107ab8e 100644
--- a/gc.c
+++ b/gc.c
@@ -924,13 +924,17 @@ assign_heap_slot(rb_objspace_t *objspace)
objs = HEAP_OBJ_LIMIT;
p = (RVALUE*)malloc(HEAP_SIZE);
+ if (p == 0) {
+ during_gc = 0;
+ rb_memerror();
+ }
slot = (struct heaps_slot *)malloc(sizeof(struct heaps_slot));
- MEMZERO((void*)slot, struct heaps_slot, 1);
-
- if (p == 0 || slot == 0) {
+ if (slot == 0) {
+ xfree(p);
during_gc = 0;
rb_memerror();
}
+ MEMZERO((void*)slot, struct heaps_slot, 1);
slot->next = heaps;
if (heaps) heaps->prev = slot;