This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

Re: malloc - egcs-2.91.66 - generates segmentation fault


>>>>> 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


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