From ef42fce3e6dcdb638ea53b651071abd4d9d83a79 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 1 Dec 1999 22:25:48 +0000 Subject: [PATCH] Fixed wrealloc() to be consistent with the wmalloc() behaviour when it cannot allocate memory. --- WINGs/memory.c | 38 +++++++++++++++++++++++++++----------- WINGs/wtabview.c | 4 ---- src/menu.c | 4 ---- src/proplist.c | 2 +- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/WINGs/memory.c b/WINGs/memory.c index d8aa69c6..dbe60c2a 100644 --- a/WINGs/memory.c +++ b/WINGs/memory.c @@ -88,10 +88,14 @@ void *wmalloc(size_t size) if (tmp == NULL) { wwarning("malloc() failed. Retrying after 2s."); sleep(2); - tmp = malloc(size); +#ifdef TEST_WITH_GC + tmp = GC_malloc(size); +#else + tmp = malloc(size); +#endif if (tmp == NULL) { if (Aborting) { - puts("Real Bad Error: recursive malloc() failure."); + fputs("Really Bad Error: recursive malloc() failure.", stderr); exit(-1); } else { wfatal("virtual memory exhausted"); @@ -109,21 +113,33 @@ void *wrealloc(void *ptr, size_t newsize) void *nptr; if (!ptr) { + nptr = wmalloc(newsize); + } else { #ifdef TEST_WITH_GC - nptr = GC_malloc(newsize); + nptr = GC_realloc(ptr, newsize); #else - nptr = malloc(newsize); + nptr = realloc(ptr, newsize); #endif - } else { + if (nptr==NULL) { + wwarning("realloc() failed. Retrying after 2s."); + sleep(2); #ifdef TEST_WITH_GC - nptr = GC_realloc(ptr, newsize); + nptr = GC_realloc(ptr, newsize); #else - nptr=realloc(ptr, newsize); + nptr = realloc(ptr, newsize); #endif - } - if (nptr==NULL) { - printf("Could not do realloc"); - return NULL; + if (nptr == NULL) { + if (Aborting) { + fputs("Really Bad Error: recursive realloc() failure.", + stderr); + exit(-1); + } else { + wfatal("virtual memory exhausted"); + Aborting=1; + wAbort(False); + } + } + } } return nptr; } diff --git a/WINGs/wtabview.c b/WINGs/wtabview.c index 549415a7..1cb520f2 100644 --- a/WINGs/wtabview.c +++ b/WINGs/wtabview.c @@ -146,10 +146,6 @@ WMInsertItemInTabView(WMTabView *tPtr, int index, WMTabViewItem *item) items = wrealloc(tPtr->items, sizeof(WMTabViewItem*) * (tPtr->maxItems + 10)); - if (!items) { - wwarning("out of memory allocating memory for tabview"); - return; - } memset(&items[tPtr->maxItems], 0, sizeof(WMTabViewItem*) * 10); tPtr->items = items; tPtr->maxItems += 10; diff --git a/src/menu.c b/src/menu.c index 0a22964d..451f6c98 100644 --- a/src/menu.c +++ b/src/menu.c @@ -294,10 +294,6 @@ wMenuInsertCallback(WMenu *menu, int index, char *text, tmp = wrealloc(menu->entries, sizeof(WMenuEntry)*(menu->alloced_entries+5)); - if (tmp==NULL) { - wwarning(_("wrealloc() failed while trying to add menu item")); - return NULL; - } menu->entries = tmp; menu->alloced_entries += 5; diff --git a/src/proplist.c b/src/proplist.c index b80aa4b2..afdfd0d9 100644 --- a/src/proplist.c +++ b/src/proplist.c @@ -373,7 +373,7 @@ get_data(FILE *f) { - COMPLAIN("the data datatype is not still implemented"); + COMPLAIN("the data datatype is not yet implemented"); return NULL; } -- 2.11.4.GIT