This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]