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-19 16:04

>>15,17
Javafag detected
This is the way things work in C, dickbag.

>>1
It will work depending on your compiler implementation.  Every C compiler that I know of manages the heap by address.  So free() doesn't care what variable name you pass to it, only what address it points to.

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