From: Francis Dupont Date: Wed, 8 Mar 2017 13:58:20 +0000 (+0100) Subject: Merged #32744 (out of memory) X-Git-Tag: v4_4_0b1_f1~113 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=66e800337ea054b227ebcf0bed97a639df613d3e;p=thirdparty%2Fdhcp.git Merged #32744 (out of memory) --- diff --git a/RELNOTES b/RELNOTES index acc7ed179..29de8f11f 100644 --- a/RELNOTES +++ b/RELNOTES @@ -981,6 +981,10 @@ by Eric Young (eay@cryptsoft.com). causing the legacy configure script to loop when run with --enable-libtool. [ISC-Bugs #43546] +- When memory allocation fails in a repeated way the process writes + "Run out of memory." on the standard error and exists with status 1. + [ISC-Bugs #32744] + Changes since 4.2.0 (new features) - If a client renews before 'dhcp-cache-threshold' percent of its lease diff --git a/omapip/alloc.c b/omapip/alloc.c index 905434466..a95ad6caf 100644 --- a/omapip/alloc.c +++ b/omapip/alloc.c @@ -52,6 +52,9 @@ int rc_history_count; static void print_rc_hist_entry (int); #endif +static int dmalloc_failures; +static char out_of_memory[] = "Run out of memory."; + void * dmalloc(size_t size, const char *file, int line) { unsigned char *foo; @@ -69,8 +72,21 @@ dmalloc(size_t size, const char *file, int line) { foo = malloc(len); - if (!foo) + if (!foo) { + dmalloc_failures++; + if (dmalloc_failures > 10) { + /* In case log_fatal() returns here */ + IGNORE_RET(write(STDERR_FILENO, + out_of_memory, + strlen(out_of_memory))); + IGNORE_RET(write(STDERR_FILENO, "\n", 1)); + exit(1); + } else if (dmalloc_failures >= 10) { + /* Something went wrong beyond repair. */ + log_fatal("Fatal error: out of memory."); + } return NULL; + } bar = (void *)(foo + DMDOFFSET); memset (bar, 0, size);