]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Merged #32744 (out of memory)
authorFrancis Dupont <fdupont@isc.org>
Wed, 8 Mar 2017 14:29:38 +0000 (15:29 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 8 Mar 2017 14:29:38 +0000 (15:29 +0100)
RELNOTES
omapip/alloc.c

index 387cc4f23ba74d5217ed8d6d8c00101b2e36499e..445acdfd26389bb48f7b565d9dcf8accd180da22 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -75,6 +75,10 @@ by Eric Young (eay@cryptsoft.com).
   Thanks to Fernando Soto at BlueCat Networks for reporting the issue.
   [ISC-Bugs #43219]
 
+- 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.1-ESV-R14b1
 - None
 
index 0d846a7a8fda95a674efe4b8d9e8816fb3bab73f..800bca73adb028cbd2ebdabad98a44b38c8f90a0 100644 (file)
@@ -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);