This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: malloc - egcs-2.91.66 - generates segmentation fault
- To: david dot svanberg at kentor dot se
- Subject: Re: malloc - egcs-2.91.66 - generates segmentation fault
- From: Andreas Jaeger <aj at suse dot de>
- Date: 21 Oct 1999 14:38:25 +0200
- Cc: gcc at gcc dot gnu dot org
- References: <380EFEC0.F2EB9BD6@lollo.lg.posten.se>
>>>>> David Svanberg writes:
> Hi.
> I'm running egcs-2.91.66 on Linux kernel release 2.2.5 (i686). The
> following code resides in a function:
> file_entry *fe;
> printf("trying to allocate %d bytes of mem...\n",
> sizeof(file_entry));
> fe = (file_entry *)malloc(sizeof(file_entry));
> if (fe == NULL)
> printf("can't allocate mem\n");
> else
> printf("memory allocated successfully!\n");
> The second call to this function gives at the third line (output from
> gdb):
> Program received signal SIGSEGV, Segmentation fault.
> 0x40072609 in chunk_free (ar_ptr=0x40102580, p=0x919542a2) at
> malloc.c:3003
> The program is successfully compiled (no warnings) with -Wall -ansi
> -pedantic. It has also been compiled and executed succesfully on a
> HPUX-machine. (And yes, I got more than 12 bytes free mem)
> Is there anyone who have heard of any bug in malloc.c (line 3003)? Are
> there any fixes? Thankful for any answers.
This is not related to gcc. malloc comes with glibc. A segmentation
fault in chunk_free signals that you've overwritten some internal data
structures of malloc. I advise to read the libc documentation for
malloc, mcheck and MALLOC_CHECK_ and find out if you're writting to
freed memory or call free twice.
The problem you report has been in all cases that I know of a bug in
the user program and not in the malloc implementation.
Andreas
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.rhein-neckar.de