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 22:39

>>33
When coding C++ or C on Windowz in Visual Studio if you free a NULL pointer it seg faults (at least in my experience). Windows <3

Name: Anonymous 2011-01-23 8:18

>>81
No. Nothing happens if you do.

Name: Anonymous 2011-01-23 11:37

>>81
Are seg faults good?

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.

Name: Anonymous 2011-01-23 13:08

>>84
In a dumb memory allocator, it just sets the "free" bit of the header of the pointer to true.

Name: Anonymous 2011-01-23 13:56

>>85
nobody does that, come on.

Name: Anonymous 2011-01-23 21:53

sizeof(char) == '1'
0

Name: Anonymous 2011-01-23 21:59

>>87 see >>86
now go away

Name: Anonymous 2011-01-23 21:59

>>87
'1'
IHBT

Name: Anonymous 2011-01-23 22:05

>>87

(imply (>implying (compiler-sizeof 'char) is #\1) being true and do (>implying displayln gets applied to "EPIC WIN OP!" and (current-output-port)) otherwise (>implying displayln gets applied to "Fuck off, >>87"))


`>imply COMBINATOR

Name: Anonymous 2011-01-23 22:06

>>81
I'm sorry Windows isn't standards-conforming.
Look at the bright side, at least you aren't using GNU. :)

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