diff options
author | Craig Tiller <ctiller@google.com> | 2015-12-09 15:50:39 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-12-09 15:50:39 -0800 |
commit | fedb761f51aaa4cd403f301d7b46acf2ed2e9589 (patch) | |
tree | cbf336d45547edd85959d6694096c20e348e657b /src/core/support/alloc.c | |
parent | df62b97299fa95f40052faff285f147cb2f0ce05 (diff) | |
parent | f9263bcfcd21efce71e90a81be96e58dd03686fc (diff) |
Merge github.com:grpc/grpc into lb_shutdown
Diffstat (limited to 'src/core/support/alloc.c')
-rw-r--r-- | src/core/support/alloc.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/core/support/alloc.c b/src/core/support/alloc.c index bfcb77956b..ca72379b1d 100644 --- a/src/core/support/alloc.c +++ b/src/core/support/alloc.c @@ -34,13 +34,27 @@ #include <grpc/support/alloc.h> #include <stdlib.h> +#include <grpc/support/log.h> #include <grpc/support/port_platform.h> #include "src/core/profiling/timers.h" +static gpr_allocation_functions g_alloc_functions = {malloc, realloc, free}; + +gpr_allocation_functions gpr_get_allocation_functions() { + return g_alloc_functions; +} + +void gpr_set_allocation_functions(gpr_allocation_functions functions) { + GPR_ASSERT(functions.malloc_fn != NULL); + GPR_ASSERT(functions.realloc_fn != NULL); + GPR_ASSERT(functions.free_fn != NULL); + g_alloc_functions = functions; +} + void *gpr_malloc(size_t size) { void *p; GPR_TIMER_BEGIN("gpr_malloc", 0); - p = malloc(size); + p = g_alloc_functions.malloc_fn(size); if (!p) { abort(); } @@ -50,13 +64,13 @@ void *gpr_malloc(size_t size) { void gpr_free(void *p) { GPR_TIMER_BEGIN("gpr_free", 0); - free(p); + g_alloc_functions.free_fn(p); GPR_TIMER_END("gpr_free", 0); } void *gpr_realloc(void *p, size_t size) { GPR_TIMER_BEGIN("gpr_realloc", 0); - p = realloc(p, size); + p = g_alloc_functions.realloc_fn(p, size); if (!p) { abort(); } |