From 2b6d2c84071f4ab4058727ce4dfc0cb8770ab930 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 16 Jan 1990 14:38:28 +0000 Subject: [PATCH] graceful degradation: allocate fewer structs if cannot get requested amount --- modules/src/alloc/st_alloc.c | 7 ++++++- modules/src/alloc/std_alloc.c | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/src/alloc/st_alloc.c b/modules/src/alloc/st_alloc.c index 8ead24486..b8c6927b6 100644 --- a/modules/src/alloc/st_alloc.c +++ b/modules/src/alloc/st_alloc.c @@ -20,7 +20,12 @@ st_alloc(phead, size, count) char *retval; if (*phead == 0) { - p = Malloc(size * count); + while (count >= 1 && (p = malloc(size * count)) == 0) { + count >>= 1; + } + if (p == 0) { + No_Mem(); + } ((_PALLOC_) p)->_A_next = 0; while (--count) { p += size; diff --git a/modules/src/alloc/std_alloc.c b/modules/src/alloc/std_alloc.c index 334581c83..381ba4017 100644 --- a/modules/src/alloc/std_alloc.c +++ b/modules/src/alloc/std_alloc.c @@ -19,8 +19,12 @@ std_alloc(phead, size, count, pcnt) register char *p; if (*phead == 0) { - - p = Malloc(size * count); + while (count >= 1 && (p = malloc(size * count)) == 0) { + count >>= 1; + } + if (p == 0) { + No_Mem(); + } *pcnt += count; ((_PALLOC_) p)->_A_next = 0; while (--count) {