summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-15 14:35:46 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-15 14:35:46 +0000
commit8923ba1ec9f7b8ebe6de729d5a54f2e2ccb202ff (patch)
treec30999087abcf6adf8034cff80025cdc666a4691 /gc.c
parent2ebd80d1157fcab65d2d854a8a094aec9a849968 (diff)
* gc.c: fix a regression by r31690 on AIX because AIX malloc
return NULL if it's passed 0. But some caller don't expect it. patch by Yutaka Kanemoto. (vm_malloc_prepare): return calculated size. (vm_xmalloc): use above result. (vm_xcalloc): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32103 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/gc.c b/gc.c
index 7bf2a123c3..f1fb7568fb 100644
--- a/gc.c
+++ b/gc.c
@@ -711,7 +711,7 @@ garbage_collect_with_gvl(rb_objspace_t *objspace)
static void vm_xfree(rb_objspace_t *objspace, void *ptr);
-static inline void
+static inline size_t
vm_malloc_prepare(rb_objspace_t *objspace, size_t size)
{
if ((ssize_t)size < 0) {
@@ -727,6 +727,8 @@ vm_malloc_prepare(rb_objspace_t *objspace, size_t size)
(malloc_increase+size) > malloc_limit) {
garbage_collect_with_gvl(objspace);
}
+
+ return size;
}
static inline void *
@@ -757,7 +759,7 @@ vm_xmalloc(rb_objspace_t *objspace, size_t size)
{
void *mem;
- vm_malloc_prepare(objspace, size);
+ size = vm_malloc_prepare(objspace, size);
TRY_WITH_GC(mem = malloc(size));
return vm_malloc_fixup(objspace, mem, size);
}
@@ -844,10 +846,12 @@ static void *
vm_xcalloc(rb_objspace_t *objspace, size_t count, size_t elsize)
{
void *mem;
- const size_t size = xmalloc2_size(count, elsize);
+ size_t size;
+
+ size = xmalloc2_size(count, elsize);
+ size = vm_malloc_prepare(objspace, size);
- vm_malloc_prepare(objspace, size);
- TRY_WITH_GC(mem = calloc(count, elsize));
+ TRY_WITH_GC(mem = calloc(1, size));
return vm_malloc_fixup(objspace, mem, size);
}