As reported by Nicolas Iooss (nicolas.iooss@xxxxxxx), static analyzers have problems understanding that the default memory error handler does not return since it is called through the cil_mem_error_handler() function pointer. This results in a number of false positive warnings about null pointer dereferencing. Since the ability to set the cil_mem_error_handler() is only through the function cil_set_mem_error_handler() which is never used and whose definition is not in any header file, remove that function, remove the use of cil_mem_error_handler() and directly in-line the contents of the default handler, cil_default_mem_error_handler(). Signed-off-by: James Carter <jwcart2@xxxxxxxxxxxxx> --- libsepol/cil/src/cil_mem.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/libsepol/cil/src/cil_mem.c b/libsepol/cil/src/cil_mem.c index 12c59be2..f73021b5 100644 --- a/libsepol/cil/src/cil_mem.c +++ b/libsepol/cil/src/cil_mem.c @@ -34,19 +34,6 @@ #include "cil_log.h" -__attribute__((noreturn)) void cil_default_mem_error_handler(void) -{ - cil_log(CIL_ERR, "Failed to allocate memory\n"); - exit(1); -} - -void (*cil_mem_error_handler)(void) = &cil_default_mem_error_handler; - -void cil_set_mem_error_handler(void (*handler)(void)) -{ - cil_mem_error_handler = handler; -} - void *cil_malloc(size_t size) { void *mem = malloc(size); @@ -54,7 +41,8 @@ void *cil_malloc(size_t size) if (size == 0) { return NULL; } - (*cil_mem_error_handler)(); + cil_log(CIL_ERR, "Failed to allocate memory\n"); + exit(1); } return mem; @@ -64,7 +52,8 @@ void *cil_calloc(size_t num_elements, size_t element_size) { void *mem = calloc(num_elements, element_size); if (mem == NULL){ - (*cil_mem_error_handler)(); + cil_log(CIL_ERR, "Failed to allocate memory\n"); + exit(1); } return mem; @@ -77,7 +66,8 @@ void *cil_realloc(void *ptr, size_t size) if (size == 0) { return NULL; } - (*cil_mem_error_handler)(); + cil_log(CIL_ERR, "Failed to allocate memory\n"); + exit(1); } return mem; @@ -94,7 +84,8 @@ char *cil_strdup(const char *str) mem = strdup(str); if (mem == NULL) { - (*cil_mem_error_handler)(); + cil_log(CIL_ERR, "Failed to allocate memory\n"); + exit(1); } return mem; @@ -110,7 +101,8 @@ __attribute__ ((format (printf, 2, 3))) int cil_asprintf(char **strp, const char va_end(ap); if (rc == -1) { - (*cil_mem_error_handler)(); + cil_log(CIL_ERR, "Failed to allocate memory\n"); + exit(1); } return rc; -- 2.21.0