On 13 Mar 2002, Bryan Paxton wrote:

> $ cat 2free.c
> #include <stdio.h>
>        #include <stdlib.h>
>
>        int main(int argc, char* argv[]) {
>            void* foo = malloc(16);
>            free(foo);
>            free(foo);
>            printf("Program ran to completion.\n");
>        }
> $  export MALLOC_CHECK=2 && gcc -o 2free 2free.c && ./2free
> Segmentation fault (core dumped)
> $

Your test program is not correct as it implies undefined behaviour per the
C standard (7.20.3.2). Therefore, it's "normal" that your test program
crashes, for example.  Should you had set foo = NULL prior to the
free()'ing the second time, well it will have to work then.

Bye,
Gwenole.


Reply via email to