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-23 13:05

Protip: What do you think free looks like?
It already takes a copy of the pointer in the argument passed it, so of course you can assign pointers back and forth between how many variables you want.

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