diff options
| author | dam <dam@gudinoff> | 2024-05-11 04:31:29 +0100 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2024-05-11 04:31:29 +0100 |
| commit | 8b934ebb39e67f1a3c9940474f69d05102b836c6 (patch) | |
| tree | 0ac6488fc95db7533b30236ebfb6cbc6f229c947 | |
| parent | e8c8132361c114bf6d90e3fb1f46004c3e09fecc (diff) | |
| download | task-time-tracker-8b934ebb39e67f1a3c9940474f69d05102b836c6.tar.zst task-time-tracker-8b934ebb39e67f1a3c9940474f69d05102b836c6.zip | |
Solved memory leak.
| -rw-r--r-- | ttt.jai | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -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; |
