From 23e4baefc2669c271f78402f5e9523d9f60a4cfe Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Wed, 13 Apr 2016 01:35:42 +0200 Subject: [PATCH] Enforcing undefined behavior of malloc. --- src/core/lib/support/alloc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/lib/support/alloc.c b/src/core/lib/support/alloc.c index 020917f79c8..618c3f6acd8 100644 --- a/src/core/lib/support/alloc.c +++ b/src/core/lib/support/alloc.c @@ -53,6 +53,7 @@ void gpr_set_allocation_functions(gpr_allocation_functions functions) { void *gpr_malloc(size_t size) { void *p; + if (size == 0) return NULL; GPR_TIMER_BEGIN("gpr_malloc", 0); p = g_alloc_functions.malloc_fn(size); if (!p) { @@ -69,6 +70,7 @@ void gpr_free(void *p) { } void *gpr_realloc(void *p, size_t size) { + if ((size == 0) && (p == NULL)) return NULL; GPR_TIMER_BEGIN("gpr_realloc", 0); p = g_alloc_functions.realloc_fn(p, size); if (!p) {