When I dynamically allocate a structure, and then try to free it, it seems to reallocate it.
typedef struct OBJ_T
{
int param1, param2;
} OBJ;
OJB* Construct(int par1, int par2)
{
OBJ* x = malloc(sizeof(OBJ));
x->param1 = par1;
x->param2 = par2;
return x;
}
void freeup(OBJ *x)
{
printf("x pointer -> %d ", x);
free(x);
x=NULL;
printf("\nx pointer -> %d\n", x);
}
int main()
{
OBJ foo = *Construct(10, 20);
freeup(&foo);
freeup(&foo);
return 0;
}
The result is:
x pointer -> 2752216
x pointer -> 0
x pointer -> 2752216
x pointer -> 0
So after freeing and nulling out the pointer, if I check it again, it goes back to what it was. Is that a problem? Or is it free and I don't have to worry about it anymore?