Many thanks to all you.
I must say that I was lucky. I had a program chashing when (after a lot of times) free() was used. Based on one comment of mats
I Inspect the value of (say) p[k] (k=-1, -2 for 32, 64 bits implementation of gcc)
Originally Posted by matsp
And just before the crash this value had changed as consecuence of another asignation, say q[ l ] = vq. With this information then I fixed my program.
I think that if the implementations of malloc() and free are known (the place for the administrative data are known) a tool for catching any unwished modification of that data could be designed.
One last favor, could you please send me the output of
with and without uncomenting the indicated lines.
#define N 100
//K = -1 for 32 bits gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
//K = -2 for 64 bits gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
#define K -1
#define NL "\n"
int main(int argc, char *argv)
int *p, n = N, k = K;
//int *q, *r;
for( i = 0; i < n; i++ )
p = malloc( sizeof( int )*i );
/* q = malloc( sizeof( int )*i );
r = malloc( sizeof( int )*i );*/
printf("\n%i %i", i, p[k]) ;
/* printf("\n%i %i", i, q[k]) ;
printf("\n%i %i", i, r[k]) ;*/
free( p );
/* free( r );
free( s );*/
printf("%s", NL );