From 8b934ebb39e67f1a3c9940474f69d05102b836c6 Mon Sep 17 00:00:00 2001 From: dam Date: Sat, 11 May 2024 04:31:29 +0100 Subject: Solved memory leak. --- ttt.jai | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/ttt.jai b/ttt.jai index 36271f2..3682bfd 100644 --- a/ttt.jai +++ b/ttt.jai @@ -37,7 +37,7 @@ VERSION :: "2.0"; // Use only 3 chars (to fit layouts). YEAR :: "2024"; NUM_WEEK_DAYS :: 7; -APP_FOLDER_NAME :: ".task_time_tracker_test"; // TODO Using different folder to avoid erasing my work data. +APP_FOLDER_NAME :: ".task_time_tracker"; DB_FILE_NAME :: "database.bin"; AR_FILE_NAME :: "archive.csv"; DB_FILE_SIGN_STR :: "TTT:B:02"; @@ -436,9 +436,10 @@ update_times :: (db: *Database) { // Keep track of this update. db.modified_on = stop_time; - if db.active_idx < 0 return; + active_task := get_active_task(db); + + if active_task == null return; - active_task := *db.tasks[db.active_idx]; start_week_day: s8; while (start_time < stop_time) { @@ -657,12 +658,15 @@ import_from_csv :: (db: *Database, path: string) -> bool #must { return result, true; } - csv, success := read_entire_file(path); + data, success := read_entire_file(path); if success == false { log_error("Failed to read file '%'.", path); return false; } - defer free(csv.data); + defer free(data); + + // Work on a string struct copy, otherwise the free(data) will fail. + csv := data; // Skip header line. consume_next_line(*csv); @@ -1403,12 +1407,7 @@ main :: () { redraw_all = key != TUI.Keys.None; update_times(*database); - - /* TODO - Remove `selected_task` and `active_task` and helper functions. - Every time we add or remove tasks to the database, it may be reallocated, thus making the selected_task and active_task pointers invalid. Check if this is messing up the app. - Maybe use a macro returns the selected/active task based on the indices. - */ + selected_task := get_selected_task(db); active_task := get_active_task(db); selected_task_row: int; -- cgit v1.2.3