From: ceriel Date: Tue, 16 Jan 1990 14:38:28 +0000 (+0000) Subject: graceful degradation: allocate fewer structs if cannot get requested amount X-Git-Tag: release-5-5~1938 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=2b6d2c84071f4ab4058727ce4dfc0cb8770ab930;p=ack.git graceful degradation: allocate fewer structs if cannot get requested amount --- 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) {