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:
parent
9a6ad5ce84
commit
adfcdb050c
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue