mirror of
https://github.com/SELinuxProject/selinux
synced 2025-03-11 04:37:29 +00:00
libsepol: Remove cil_mem_error_handler() function pointer
As reported by Nicolas Iooss (nicolas.iooss@m4x.org), 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@tycho.nsa.gov>
This commit is contained in:
parent
dc4e54126b
commit
4459d635b8
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user