I have a question about this code:
typedef struct pop {
unsigned long int *np; // matrix
unsigned long int f;
long double fp;
unsigned long int *R; // matrix
unsigned long int *C; // matrix
unsigned long int Dp;
unsigned long int Ds;
unsigned long int count;
struct popolazione *ptrTempLst; // pointer
struct popolazione *leftTree; // left tree pointer
struct popolazione *rightTree; // right tree pointer
} Node;
When I free space allocated for this struct, prior have I to free pointer to matrix inside struct?
For example,
Node *ptr=(Node *) malloc(sizeOf(Node));
ptr->np=(unsigned long int *)malloc(10*sizeOf(unsigned long int));
/*code code code*/
// is necessary: free(ptr->np);
free(ptr);
Thanks in advance
Yes.
Every call to malloc
must have a matching call to free
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With