summaryrefslogtreecommitdiff
path: root/omapip
diff options
context:
space:
mode:
authorFrancis Dupont <fdupont@isc.org>2017-03-08 14:58:20 +0100
committerFrancis Dupont <fdupont@isc.org>2017-03-08 14:58:20 +0100
commit66e800337ea054b227ebcf0bed97a639df613d3e (patch)
tree6e5f961be920ed1a4b93bd7ddf6fe27a202b6293 /omapip
parent2c8a396ad24757817a08ad6d3da915a1aca8d381 (diff)
downloadisc-dhcp-66e800337ea054b227ebcf0bed97a639df613d3e.tar.gz
Merged #32744 (out of memory)
Diffstat (limited to 'omapip')
-rw-r--r--omapip/alloc.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/omapip/alloc.c b/omapip/alloc.c
index 90543446..a95ad6ca 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);