diff --git a/src/planner.c b/src/planner.c index 2ea0a92..909f385 100644 --- a/src/planner.c +++ b/src/planner.c @@ -43,6 +43,26 @@ void llistPrintE(llist *head) { c = c->next; } } +void freeEvent(Event *e) { + free(e->task); + free(e); +} +void llistFreeE(llist *head) { + while (head != NULL) { + free((Event *)head->data); + llist *tmp = head; + head = head->next; + free(tmp); + } +} +void llistFreeT(llist *head) { + while (head != NULL) { + free(head->data); + llist *tmp = head; + head = head->next; + free(tmp); + } +} void planLog(char *msg, bool e) { if (!e) printf("[Planner][log] %s\n", msg); diff --git a/src/planner.h b/src/planner.h index 9d0c3d9..c390e47 100644 --- a/src/planner.h +++ b/src/planner.h @@ -41,6 +41,7 @@ char *taskToStr(Task *t); * prints human readable str of Task to stdout */ void printTask(Task *s); +void llistFreeT(llist *head); /* * create deepCopy of task @@ -74,6 +75,8 @@ Event *newEvent(Task *t, time_t s, time_t e, uint64_t sp); /* * compare function for Event */ +void freeEvent(Event *e); +void llistFreeE(llist *head); int cmpEvent(const void *a, const void *b); /* * takes llist of tasks and returns llist of events diff --git a/src/test.c b/src/test.c index c3a61c5..0a5f98c 100644 --- a/src/test.c +++ b/src/test.c @@ -33,7 +33,8 @@ int main() { llistAppend(list1, t3); llistAppend(list1, t4); - genPlan(list1); + llist *l1 = genPlan(list1); + llistFreeE(l1); // print test tasks printTask(t1); @@ -53,10 +54,8 @@ int main() { char *t1Str = taskToStr(t1); printf("%s\n", t1Str); + llistFreeT(list1); free(t1Str); - free(t1); - free(t2); - return 0; }