Say I had the following simple example
#include <stdlib.h>
#include <stdio.h>
struct x {
int* p;
};
typedef struct y {
x* foo;
}real;
void doSomething();
int main() {
doSomething();
getchar();
return 0;
}
void doSomething() {
real* tmp = (real*)malloc(sizeof(real));
tmp->foo = (x*)malloc(sizeof(x));
free(tmp->foo);
free(tmp);
}
Is it necessary to free the pointer I allocated inside before I free the "outer" allocated memory?
would the second line take care of the first allocated memory...my assumption is no(it will still remain on the heap I assume and I would need to keep it this way).