summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/gc.c b/gc.c
index c79fd73dc9..341863d8d4 100644
--- a/gc.c
+++ b/gc.c
@@ -3529,7 +3529,14 @@ vm_xrealloc(rb_objspace_t *objspace, void *ptr, size_t size)
if ((ssize_t)size < 0) {
negative_size_allocation_error("negative re-allocation size");
}
+
if (!ptr) return vm_xmalloc(objspace, size);
+
+ /*
+ * The behavior of realloc(ptr, 0) is implementation defined.
+ * Therefore we don't use realloc(ptr, 0) for portability reason.
+ * see http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_400.htm
+ */
if (size == 0) {
vm_xfree(objspace, ptr);
return 0;