From: Daniel Liu Date: Tue, 16 Feb 2021 20:01:44 +0000 (-0500) Subject: free board X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=b1a5da51ad170de714ed6b0b7a566f867cde6c16;p=taskasaur.git free board --- diff --git a/headers/parser.h b/headers/parser.h index e924f3e..1bf2ae3 100644 --- a/headers/parser.h +++ b/headers/parser.h @@ -45,6 +45,7 @@ typedef struct Board { extern Board* begin_parse(char* board_path); extern int begin_write(char* board_path, Board* board); extern void log_todo(Board* board); +extern int free_board(Board* board); #ifdef __cplusplus } diff --git a/menu.c b/menu.c index d66ee07..e9071d6 100644 --- a/menu.c +++ b/menu.c @@ -50,7 +50,7 @@ create_menuitem(char* title) new_menuitem = malloc(sizeof(MenuItem)); new_menuitem->title = title; - new_menuitem->description = 0; //TEMP FOR NOW + new_menuitem->description = strdup(""); //TEMP FOR NOW return new_menuitem; } diff --git a/parser.c b/parser.c index 89c1ec0..b752085 100644 --- a/parser.c +++ b/parser.c @@ -381,3 +381,33 @@ log_todo(Board* board) } } } + +int +free_board(Board* board) +{ // all the fields are being leaked rn + + for (int i = 0; i < board->todolist_count; i++) { + TodoList* cur_todolist = board->todolist_list[i]; + + /* free(cur_todolist->list_name); */ + + for (int j = 0; j < cur_todolist->item_count; j++) { + TodoItem* cur_todoitem = cur_todolist->item_list[j]; + + /* free(cur_todoitem->item_name); */ + /* free(cur_todoitem->description); */ + /* free(cur_todoitem->due); */ + + /* free subtask later too */ + + free(cur_todoitem); + } + + free(cur_todolist); + } + + /* free(board->board_name); */ + free(board); + + return 0; +} diff --git a/taskasaur.c b/taskasaur.c index 353ca5d..d3b8ba8 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -171,14 +171,10 @@ main(int argc, char** argv) case BINDING_WRITE: { Board* writeboard; - writeboard = boardmenu_to_board(boardmenu); - /* mvprintw(30, 5, "%s", writeboard->todolist_list[0]->list_name); */ begin_write(boardfile_name, writeboard); - - /* now free the writeborad */ - + free_board(writeboard); } break; @@ -221,8 +217,8 @@ boardmenu_to_board(BoardMenu* boardmenu) Menu* curmenu = boardmenu->menu_list[i]; TodoList* new_todolist = malloc(sizeof(TodoList)); - TodoItem** item_list = malloc(sizeof(TodoItem*)); - new_todolist->list_name = get_menu_name(curmenu); + TodoItem** new_item_list = malloc(sizeof(TodoItem*)); + new_todolist->list_name = strdup(get_menu_name(curmenu)); new_todolist->item_count = get_menu_length(curmenu); for (int j = 0; j < get_menu_length(curmenu); j++) { @@ -230,22 +226,21 @@ boardmenu_to_board(BoardMenu* boardmenu) TodoItem* new_todoitem = malloc(sizeof(TodoItem)); - new_todoitem->item_name = get_menuitem_title(curmenuitem); - new_todoitem->description = get_menuitem_descrip(curmenuitem); - new_todoitem->due = 0; //TEMP! - new_todoitem->subtask_list = 0; //TEMP! + new_todoitem->item_name = strdup(get_menuitem_title(curmenuitem)); + new_todoitem->description = strdup(get_menuitem_descrip(curmenuitem)); + new_todoitem->due = strdup(""); //TEMP! + new_todoitem->subtask_list = malloc(0); //TEMP! new_todoitem->subtask_count = 0; //TEMP! - item_list[j] = new_todoitem; - + new_item_list[j] = new_todoitem; } - new_todolist->item_list = item_list; - + new_todolist->item_list = new_item_list; new_todolist_list[i] = new_todolist; } + newboard->board_name = strdup(""); newboard->todolist_list = new_todolist_list; newboard->todolist_count = boardmenu->menu_count;