From f1fce96a1d8026474b2cd56a855fd001cfd108b6 Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Tue, 4 Aug 2020 23:28:16 +0100 Subject: config: handle allocation failure explicitly --- xmalloc.h | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 xmalloc.h (limited to 'xmalloc.h') diff --git a/xmalloc.h b/xmalloc.h new file mode 100644 index 00000000..d4e48f79 --- /dev/null +++ b/xmalloc.h @@ -0,0 +1,10 @@ +#pragma once + +#include +#include +#include "macros.h" + +void *xmalloc(size_t size) XMALLOC; +void *xcalloc(size_t nmemb, size_t size) XMALLOC; +char *xstrdup(const char *str) XSTRDUP; +char *xasprintf(const char *format, ...) PRINTF(1) XMALLOC; -- cgit v1.3 From 014019e98da7fa0f7476bea5b6f3c84dafe7558a Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Wed, 5 Aug 2020 20:11:51 +0100 Subject: xmalloc: log error to syslog() in fatal_error() function --- xmalloc.c | 3 +++ xmalloc.h | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'xmalloc.h') diff --git a/xmalloc.c b/xmalloc.c index aecb5787..7322953a 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -2,11 +2,14 @@ #include #include #include +#include +#include #include "xmalloc.h" static NORETURN COLD void fatal_error(const char *msg, int err) { + syslog(LOG_ERR, "%s: %s", msg, strerror(err)); errno = err; perror(msg); abort(); diff --git a/xmalloc.h b/xmalloc.h index d4e48f79..90d63031 100644 --- a/xmalloc.h +++ b/xmalloc.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include "macros.h" void *xmalloc(size_t size) XMALLOC; -- cgit v1.3