This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
malloc question
- From: Sebastien Decugis <sebastien dot decugis at ext dot bull dot net>
- To: libc-alpha at sources dot redhat dot com
- Date: Mon, 26 Apr 2004 18:56:51 +0200
- Subject: malloc question
Hi,
I am trying to check the behavior of some of the libc functions when the
system is running out of memory.
My first attempt to obtain this is a loop like this (note that SIZEBLK
is just a shortcut, it may be defined to value 1):
void * ptr, *ptr_prev=NULL;
/* Allocate all available memory */
while (1)
{
ptr = malloc(SIZEBLK * sizeof(void*));
if (ptr == NULL)
break;
*(void **)ptr = ptr_prev;
ptr_prev = ptr;
}
if (errno != ENOMEM)
UNRESOLVED(errno, "Memory not full");
/* Here no memory left */
/* Let's free memory */
while (ptr_prev != NULL)
{
ptr = ptr_prev;
ptr_prev = *(void **)ptr;
free(ptr);
}
The problem is that my process is killed when no memory is left. Is that
a wanted behavior? The posix standard requires the function to return
NULL and set errno to ENOMEM. Is this behavior dependent on my linux
distribution (RH9)?
A last question: Does anybody knows a way to go near memory limit
without being killed?
Thanks everyone.
Sebastien.
--
Sébastien DECUGIS
Bull S.A.
NPTL Tests & Trace project
http://nptl.bullopensource.org