From 8734fa6ae4ba18afa6b232fdfaa42b9bc0a3aec4 Mon Sep 17 00:00:00 2001 From: nova Date: Mon, 12 Jan 2026 18:35:38 +0100 Subject: [PATCH] -fsanitize=address related compiler assisted debugging --- dir.c | 1 + file_previews.c | 1 + main.c | 1 + threading.c | 38 +++++++++++++++++++++----------------- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/dir.c b/dir.c index b60ed6f..fa84512 100644 --- a/dir.c +++ b/dir.c @@ -315,6 +315,7 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file } else { wattroff(win, COLOR_PAIR(dir_content[i].color_pair)); } + free(file_name); } free(bg); diff --git a/file_previews.c b/file_previews.c index ba4ba49..e0f441e 100644 --- a/file_previews.c +++ b/file_previews.c @@ -33,6 +33,7 @@ char* get_mimetype(char *path){ FILE *cmd_open = popen(cmd, "r"); char *line = NULL; size_t size = 0; + free(cmd); if (getline(&line, &size, cmd_open) != -1){ pclose(cmd_open); return line; diff --git a/main.c b/main.c index 632f50b..032de70 100644 --- a/main.c +++ b/main.c @@ -91,6 +91,7 @@ int main(){ temp_heigth = terminal_height; } if (status & STATUS_RUN_BACKEND) { + free(global_path); global_path = getcwd(NULL, 0); pthread_cond_signal(&cond_top); pthread_cond_signal(&cond_mid); diff --git a/threading.c b/threading.c index 2286f64..89b0b9c 100644 --- a/threading.c +++ b/threading.c @@ -165,9 +165,7 @@ void *thread_rgt(){ path = malloc(sizeof(char)); path[0] = '\0'; } - file_current.file_type = mid_content[selected_file_current].file_type; - file_current.file_size = mid_content[selected_file_current].file_size; - file_current.status = mid_content[selected_file_current].status; + memcpy(&file_current, &mid_content[selected_file_current], sizeof(file)); pthread_mutex_unlock(&mutex_mid); if (mid_content[selected_file_current].permissions & S_IRUSR) { @@ -185,14 +183,20 @@ void *thread_rgt(){ free(rgt_content); rgt_file_count = get_dir_size(path); - rgt_content = malloc(rgt_file_count * sizeof(file)); - memset(rgt_content, '\0', rgt_file_count * sizeof(file)); - get_dir_content(path, &rgt_file_count, rgt_content); - rgt_content[0].status &= ~FILE_STATUS_FILE_OPEN; + if (rgt_file_count) { /* fails if dir empty */ + rgt_content = malloc(rgt_file_count * sizeof(file)); + memset(rgt_content, '\0', rgt_file_count * sizeof(file)); + get_dir_content(path, &rgt_file_count, rgt_content); + rgt_content[0].status &= ~FILE_STATUS_FILE_OPEN; - free(rgt_buffer); - rgt_buffer = malloc(sizeof(char)); - rgt_buffer[0] = '\0'; + free(rgt_buffer); + rgt_buffer = malloc(sizeof(char)); + rgt_buffer[0] = '\0'; + } else { /* the hovered dir is empty */ + rgt_content = malloc(sizeof(file)); + rgt_content->file_type = 0; + rgt_content->permissions = mid_content[selected_file_current].permissions; + } } else if ((status & STATUS_DELTA_TIME) != STATUS_DELTA_TIME) { unsigned long i = 0; @@ -282,6 +286,9 @@ void *thread_btm(){ free(ui_btm_right_block); + if(path) { + free(path); + } path = getcwd(NULL, 0); struct statvfs fs; statvfs(path, &fs); @@ -338,10 +345,9 @@ void *thread_btm(){ if (buffer_width != terminal_width) { buffer_width = terminal_width; free(btm_buffer); - btm_buffer = malloc(buffer_width); - memset(btm_buffer, ' ', buffer_width/2); + btm_buffer = malloc(buffer_width+1); } - memset(btm_buffer + (buffer_width/2), ' ', buffer_width/2); + memset(btm_buffer, ' ', buffer_width); btm_buffer[buffer_width] = '\0'; memcpy(btm_buffer + buffer_width - ui_btm_right_block_size, ui_btm_right_block, ui_btm_right_block_size); @@ -379,13 +385,11 @@ void threading_init(){ mid_content->file_type = 0; mid_content->file_size = 0; - mid_content->file_name = malloc(sizeof(char)); - mid_content->file_name[0] = '\0'; + mid_content->file_name = ""; rgt_content->file_type = 0; rgt_content->file_size = 0; - rgt_content->file_name = malloc(sizeof(char)); - rgt_content->file_name[0] = '\0'; + rgt_content->file_name = ""; volatile char vol; /* needed to make sure higher optimization steps dont move these around */