malloc

Tim Brown tim at comcon.UUCP
Mon Dec 10 09:00:31 AEST 1990


Does anyone know why this code should core dump?

-----------------------
1.
first in main():
	names = NULL;
----------------------
2.
Then:
	if(some_condition && names != NULL)
	{
		free(names);
		names = NULL;
	}
----------------------
3.
Then:
	if(names == NULL)
		if((names = (char *)malloc(BUFF_SIZE)) == NULL)
		{
			perror("malloc");
			exit(errno);
		}
-------------------------

I set this up by setting the char *names equal to NULL at run time and
then when I want to change the memory allocation, I free(names) and
once again set names = NULL, that way I can call the malloc code
repeatedly allocating a different size chunk each time.  I want to be
able to run chunks 2&3 repeatedly.

On my system, ISC2.2, it core dumps on the third time thru.  On an
IBM6000, it works as expected.  I suspect a bug in ISC's malloc.  How
are others doing this?  

It core dumps at the malloc according to sdb.

I know this is comp.lang.c stuff but it seems to possibly be isolated
to ISC.

Thanks for any help.

-- 
Tim Brown            |
Computer Connection  |
uunet!seaeast.wa.com!comcon!tim    |



More information about the Comp.unix.sysv386 mailing list