I am coding a program where a pointer STR *pt
to a STR
type structure that I am using (basically an array of STR
structures with which I want to use dynamic memory) might takes a NULL
value as sometimes I don't want to store any array trough it, so when I use free(pt)
over that pointer I get a segmentation fault. What I want is to check it that pointer has a NULL
value, but when I check if(pt != NULL) free(pt);
(I only want to free memory when pointer is not NULL
), condition is always true, pointer is tryed to be freed and segmentation fault happens.
Is there any way to solve this problem? Another way to compare pointer values?