aboutsummaryrefslogtreecommitdiffstats
path: root/gc.c
diff options
context:
space:
mode:
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/gc.c b/gc.c
index 6ce83469e6..5aac9738e3 100644
--- a/gc.c
+++ b/gc.c
@@ -866,8 +866,10 @@ vm_xfree(rb_objspace_t *objspace, void *ptr)
size_t size;
ptr = ((size_t *)ptr) - 1;
size = ((size_t*)ptr)[0];
- objspace->malloc_params.allocated_size -= size;
- objspace->malloc_params.allocations--;
+ if (size) {
+ objspace->malloc_params.allocated_size -= size;
+ objspace->malloc_params.allocations--;
+ }
#endif
free(ptr);
@@ -950,7 +952,8 @@ ruby_mimmalloc(size_t size)
#endif
mem = malloc(size);
#if CALC_EXACT_MALLOC_SIZE
- ((size_t *)mem)[0] = size;
+ /* set 0 for consistency of allocated_size/allocations */
+ ((size_t *)mem)[0] = 0;
mem = (size_t *)mem + 1;
#endif
return mem;