autoupdater: Add safe_malloc function

safe_malloc is a wrapper around malloc that aborts the current
process if the memory allocation fails

Signed-off-by: Tobias Schramm <tobleminer@gmail.com>
This commit is contained in:
Tobias Schramm 2018-02-20 12:03:25 +01:00
parent 9a6ad5ce84
commit adfcdb050c
2 changed files with 13 additions and 0 deletions

View File

@ -100,3 +100,15 @@ float get_uptime(void) {
fputs("autoupdater: error: unable to determine uptime\n", stderr);
exit(1);
}
void *safe_malloc(size_t size, char *errmsg) {
void *ret = malloc(size);
if (ret)
return ret;
if (errmsg)
fprintf(stderr, "autoupdater: error: %s\n", errmsg);
abort();
}

View File

@ -28,3 +28,4 @@
void run_dir(const char *dir);
void randomize(void);
float get_uptime(void);
void *safe_malloc(size_t size, char *errmsg);