diff --git a/admin/autoupdater/src/util.c b/admin/autoupdater/src/util.c index 881523f..ff21d4f 100644 --- a/admin/autoupdater/src/util.c +++ b/admin/autoupdater/src/util.c @@ -100,3 +100,23 @@ float get_uptime(void) { fputs("autoupdater: error: unable to determine uptime\n", stderr); exit(1); } + +void * safe_malloc(size_t size) { + void *ret = malloc(size); + if (!ret) { + fprintf(stderr, "autoupdater: error: failed to allocate memory\n"); + abort(); + } + + return ret; +} + +void * safe_realloc(void *ptr, size_t size) { + void *ret = realloc(ptr, size); + if (!ret) { + fprintf(stderr, "autoupdater: error: failed to allocate memory\n"); + abort(); + } + + return ret; +} diff --git a/admin/autoupdater/src/util.h b/admin/autoupdater/src/util.h index 5c23d79..305cc3a 100644 --- a/admin/autoupdater/src/util.h +++ b/admin/autoupdater/src/util.h @@ -24,7 +24,12 @@ */ #pragma once +#include + void run_dir(const char *dir); void randomize(void); float get_uptime(void); + +void * safe_malloc(size_t size); +void * safe_realloc(void *ptr, size_t size);