fixed mem bug

planner
simon 2024-12-13 18:07:35 +01:00
parent 568c1dcf7d
commit 5bbfc52403
1 changed files with 21 additions and 8 deletions

View File

@ -38,7 +38,7 @@ void printEvent(Event *s) {
ctime_r(&s->plannedStartTime, st); ctime_r(&s->plannedStartTime, st);
ctime_r(&s->plannedEndTime, e); ctime_r(&s->plannedEndTime, e);
printf(eventFormat, s->task->name, st, e, s->spare); printf(eventFormat, s->task->name, st, e, s->spare);
printTask(s->task); // printTask(s->task);
} }
void llistPrintE(llist *head) { void llistPrintE(llist *head) {
llist *c = head; llist *c = head;
@ -203,6 +203,9 @@ llist *genPlan(llist *head, time_t timeAvail) {
time_t now = time(NULL); time_t now = time(NULL);
struct tm *lc = localtime(&now); struct tm *lc = localtime(&now);
llist *events_ll = llistNew(NULL, cmpEvent); llist *events_ll = llistNew(NULL, cmpEvent);
if (events_ll == NULL) {
exit(1);
}
// time_t avail = mktime(timeAvail); // time_t avail = mktime(timeAvail);
time_t start, end; time_t start, end;
// (mktime(lc) < mktime(timeAvail)) // (mktime(lc) < mktime(timeAvail))
@ -211,10 +214,15 @@ llist *genPlan(llist *head, time_t timeAvail) {
lc->tm_min += intervalLen; lc->tm_min += intervalLen;
end = mktime(lc); // end = mktime(lc); //
Event *c = llist *tmp = llistGet(head, sortedPrio);
newEvent(sortedPrio, start, end, 0); // use elem with wighest priority Event *c = NULL;
if (tmp != NULL) {
c = newEvent(tmp->data, start, end,
0); // use elem with wighest priority
}
llistAppend(events_ll, c); llistAppend(events_ll, c);
printEvent(c); // printEvent(c);
// printEvent((Event *)((events_ll)->next)->data);
// decrement priority of first elem and resort list // decrement priority of first elem and resort list
(*sortedPrio).priority -= 1; (*sortedPrio).priority -= 1;
@ -246,12 +254,17 @@ llist *genPlan(llist *head, time_t timeAvail) {
llistFreeE(tmp); llistFreeE(tmp);
llistPrintE(events_ll); llistPrintE(events_ll);
// for (int i = 0; i < lLen; i++) { // update prioriteis in original llist
// printTask(sortedPrio + i); for (int i = 0; i < lLen; i++) {
// } llist *tmp = llistGet(head, sortedPrio + i);
if (tmp != NULL) {
((Task *)(tmp->data))->priority = sortedPrio[i].priority;
}
}
free(sortedPrio);
planLog("END GEN PLAN", 0); planLog("END GEN PLAN", 0);
llistFreeT(head); // llistFreeT(head);
// send updated tasks to db for storage // send updated tasks to db for storage
return events_ll; return events_ll;