Automatically free container elements if needed

This commit is contained in:
2024-10-26 09:45:22 +11:00
parent 3148a56ce0
commit 2ee19c7c66
4 changed files with 21 additions and 7 deletions

View File

@@ -19,9 +19,12 @@ Toy_Stack* Toy_allocateStack() {
}
void Toy_freeStack(Toy_Stack* stack) {
//TODO: slip in a call to free the complex values here
if (stack != NULL) {
//if some values will be removed, free them first
for (unsigned int i = 0; i < stack->count; i++) {
Toy_freeValue(stack->data[i]);
}
free(stack);
}
}