I have an algorithm in c in which memory is allocated using malloc many times. I wanted to write a function that would free that memory when the program is all finished but I am unsure how to structure it. Would it just be multiple calls to free()
? I am rather new to C and memory allocation so any help would be greatly appreciated.
Program:
typedef struct State State;
typedef struct Suffix Suffix;
struct State { /* prefix + suffix list */
char* pref[NPREF]; /* prefix words */
Suffix* suf; /* list of suffixes */
State* next; /* next in hash table */
};
struct Suffix { /* list of suffixes */
char * word; /* suffix */
Suffix* next; /* next in list of suffixes */
};