amd64 - strange behavior in simple C application - malloc() issue?

From: Ted Sung (teds_at_intex.com)
Date: 08/23/04


Date: 23 Aug 2004 06:39:57 -0700

I don't understand why this is happening on This occurs on my AMD 64
machine, running SuSe Linux, GCC 3.2.2

Here are 2 simple C applications:

This program works -

#include <stdlib.h>
int main( void ) {
int * tmp = (int *)malloc( 131049 ) ;
free( (int*)tmp ) ;
exit 0 ;
}

This program FAILS with a core dump.

// #include <stdlib.h>
int main( void ) {
int * tmp = (int *)malloc( 131049 ) ;
free( (int*)tmp ) ;
exit 0 ;
}

I noticed that 131048 (=32762 4 byte units, suspiciously near 2^^15 =
32768) will WORK in the crashing version of the program.

It looks there is some default prototyping of malloc() when the
stdlib.h is not
included which is causing the free to crash the second program.

Any ideas?

Thanks,

Ted


Quantcast