Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

malloc() and free()

Name: Anonymous 2011-01-18 22:44

#include <stdlib.h>

int * b;

int main(void)
{
    int * a = NULL;
    a = (int *) malloc(sizeof(int));
    b = &a;
    free(b);
    return 0;
}


Would this result in a memory leak? If yes, why?

Name: Anonymous 2011-01-22 10:35

there is no memory leak OP. a and b points to the same memory. once you free one of them that memory location is unallocated and both pointers are invalid.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List