diff options
-rw-r--r-- | test/core/util/memory_counters.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/test/core/util/memory_counters.c b/test/core/util/memory_counters.c index 0a782b3470..fd6770bd49 100644 --- a/test/core/util/memory_counters.c +++ b/test/core/util/memory_counters.c @@ -49,10 +49,14 @@ static void guard_free(void *vptr); static void *guard_malloc(size_t size) { size_t *ptr; if (!size) return NULL; - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_absolute, size); - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_relative, size); - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_allocs_absolute, 1); - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_allocs_relative, 1); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_absolute, + (gpr_atm)size); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_relative, + (gpr_atm)size); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_allocs_absolute, + (gpr_atm)1); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_allocs_relative, + (gpr_atm)1); ptr = g_old_allocs.malloc_fn(size + sizeof(size)); *ptr++ = size; return ptr; @@ -68,10 +72,14 @@ static void *guard_realloc(void *vptr, size_t size) { return NULL; } --ptr; - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_absolute, size); - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_relative, -*ptr); - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_relative, size); - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_allocs_absolute, 1); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_absolute, + (gpr_atm)size); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_relative, + -(gpr_atm)*ptr); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_relative, + (gpr_atm)size); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_allocs_absolute, + (gpr_atm)1); ptr = g_old_allocs.realloc_fn(ptr, size + sizeof(size)); *ptr++ = size; return ptr; @@ -81,8 +89,10 @@ static void guard_free(void *vptr) { size_t *ptr = vptr; if (!vptr) return; --ptr; - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_relative, -*ptr); - gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_allocs_relative, -1); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_size_relative, + -(gpr_atm)*ptr); + gpr_atm_no_barrier_fetch_add(&g_memory_counters.total_allocs_relative, + -(gpr_atm)1); g_old_allocs.free_fn(ptr); } |