From a4930e196933f602e975028cfd8373d20381e60c Mon Sep 17 00:00:00 2001 From: Tony Finch Date: Mon, 13 Jun 2022 12:00:01 +0100 Subject: [PATCH] Improve DBC in isc_mem_free Unlike standard free(), isc_mem_free() is not a no-op when passed a NULL pointer. For size accounting purposes it calls sallocx(), which crashes when passed a NULL pointer. To get more helpful diagnostics, REQUIRE() that the pointer is not NULL so that when the programmer makes a mistake they get a backtrace that shows what went wrong. --- lib/isc/mem.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/isc/mem.c b/lib/isc/mem.c index 767f910c13..a68d7d6766 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -981,6 +981,7 @@ isc__mem_free(isc_mem_t *ctx, void *ptr FLARG) { size_t size = 0; REQUIRE(VALID_CONTEXT(ctx)); + REQUIRE(ptr != NULL); size = sallocx(ptr, 0);