mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-20 21:08:08 +01:00
Fixed wrealloc() to be consistent with the wmalloc() behaviour when it cannot
allocate memory.
This commit is contained in:
@@ -88,10 +88,14 @@ void *wmalloc(size_t size)
|
|||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
wwarning("malloc() failed. Retrying after 2s.");
|
wwarning("malloc() failed. Retrying after 2s.");
|
||||||
sleep(2);
|
sleep(2);
|
||||||
|
#ifdef TEST_WITH_GC
|
||||||
|
tmp = GC_malloc(size);
|
||||||
|
#else
|
||||||
tmp = malloc(size);
|
tmp = malloc(size);
|
||||||
|
#endif
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
if (Aborting) {
|
if (Aborting) {
|
||||||
puts("Real Bad Error: recursive malloc() failure.");
|
fputs("Really Bad Error: recursive malloc() failure.", stderr);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
} else {
|
} else {
|
||||||
wfatal("virtual memory exhausted");
|
wfatal("virtual memory exhausted");
|
||||||
@@ -109,21 +113,33 @@ void *wrealloc(void *ptr, size_t newsize)
|
|||||||
void *nptr;
|
void *nptr;
|
||||||
|
|
||||||
if (!ptr) {
|
if (!ptr) {
|
||||||
#ifdef TEST_WITH_GC
|
nptr = wmalloc(newsize);
|
||||||
nptr = GC_malloc(newsize);
|
|
||||||
#else
|
|
||||||
nptr = malloc(newsize);
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
#ifdef TEST_WITH_GC
|
#ifdef TEST_WITH_GC
|
||||||
nptr = GC_realloc(ptr, newsize);
|
nptr = GC_realloc(ptr, newsize);
|
||||||
#else
|
#else
|
||||||
nptr=realloc(ptr, newsize);
|
nptr = realloc(ptr, newsize);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
if (nptr==NULL) {
|
if (nptr==NULL) {
|
||||||
printf("Could not do realloc");
|
wwarning("realloc() failed. Retrying after 2s.");
|
||||||
return NULL;
|
sleep(2);
|
||||||
|
#ifdef TEST_WITH_GC
|
||||||
|
nptr = GC_realloc(ptr, newsize);
|
||||||
|
#else
|
||||||
|
nptr = realloc(ptr, newsize);
|
||||||
|
#endif
|
||||||
|
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;
|
return nptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,10 +146,6 @@ WMInsertItemInTabView(WMTabView *tPtr, int index, WMTabViewItem *item)
|
|||||||
|
|
||||||
items = wrealloc(tPtr->items,
|
items = wrealloc(tPtr->items,
|
||||||
sizeof(WMTabViewItem*) * (tPtr->maxItems + 10));
|
sizeof(WMTabViewItem*) * (tPtr->maxItems + 10));
|
||||||
if (!items) {
|
|
||||||
wwarning("out of memory allocating memory for tabview");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
memset(&items[tPtr->maxItems], 0, sizeof(WMTabViewItem*) * 10);
|
memset(&items[tPtr->maxItems], 0, sizeof(WMTabViewItem*) * 10);
|
||||||
tPtr->items = items;
|
tPtr->items = items;
|
||||||
tPtr->maxItems += 10;
|
tPtr->maxItems += 10;
|
||||||
|
|||||||
@@ -294,10 +294,6 @@ wMenuInsertCallback(WMenu *menu, int index, char *text,
|
|||||||
|
|
||||||
tmp = wrealloc(menu->entries,
|
tmp = wrealloc(menu->entries,
|
||||||
sizeof(WMenuEntry)*(menu->alloced_entries+5));
|
sizeof(WMenuEntry)*(menu->alloced_entries+5));
|
||||||
if (tmp==NULL) {
|
|
||||||
wwarning(_("wrealloc() failed while trying to add menu item"));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
menu->entries = tmp;
|
menu->entries = tmp;
|
||||||
menu->alloced_entries += 5;
|
menu->alloced_entries += 5;
|
||||||
|
|||||||
@@ -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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user