This is the mail archive of the
glibc-linux@ricardo.ecn.wfu.edu
mailing list for the glibc project.
malloc is thrashing my system, please HELP
- To: "Linux glibc" <glibc-linux at ricardo dot ecn dot wfu dot edu>
- Subject: malloc is thrashing my system, please HELP
- From: "Roland Schwarz" <roland dot schwarz at chello dot at>
- Date: Thu, 15 Mar 2001 10:37:44 +0100
- Reply-To: glibc-linux at ricardo dot ecn dot wfu dot edu
Please anyone help,
I do not know what is going wrong. I am trying to allocate memory until
malloc cannot fullfill my requests anymore. Instead of returning a NULL
pointer my system freezes.
Am I doing something stupid anyway? What can I do to prevent this case?
BTW on a system without virtual memory, I get a bus error instead.
Can I use a 'Low water mark' or something else to stop requesting memory,
before malloc would return NULL?
The program is:
#include <stdio.h>
#include <malloc.h>
struct list {
struct list* pNext;
};
int main(int argc, char* argv[]) {
struct list* pTop;
struct list* pBottom;
struct list* pl;
pTop = malloc(sizeof(struct list) + 4096);
pTop->pNext = NULL;
pBottom = pTop;
while((pl = malloc(sizeof(struct list) + 4096))) {
pl->pNext = NULL;
pBottom->pNext = pl;
pBottom = pl;
}
printf("exhausted\n");
pl = pTop;
while (pl) {
pl = pl->pNext;
free(pl);
}
printf("freed\n");
return 0;
}