From f1b14001942354eacc824a833d28880c1d581a49 Mon Sep 17 00:00:00 2001 From: nova Date: Thu, 18 Jun 2026 21:54:51 +0200 Subject: [PATCH] fix of copy_file --- interactions.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/interactions.c b/interactions.c index ec845a7..cc15b50 100644 --- a/interactions.c +++ b/interactions.c @@ -480,12 +480,6 @@ void copy_file(unsigned long passes, int index){ unsigned long i; unsigned long j = 0; - char *path = malloc(strlen(global_path)+1); /* im at a loss for words, freeing this always segfaults if yank_files.count != 0 - if i use global_path directly or getcwd(NULL, 0), it will segfault at the next free on global_path. - what makes this wierder is, regardless of if the yank_files.count != 0 is true or false, both do the same things - so were going to just leak the size of the path */ - - memcpy(path, global_path, strlen(global_path)+1); if (yank_files.count != 0) { for (i = 0; i < yank_files.count; i++) { @@ -506,30 +500,28 @@ void copy_file(unsigned long passes, int index){ for (i = 0; j < yank_files.count; i++) { if (mid_dir.file_list[i].status & FILE_STATUS_SELECTED) { - char *str = malloc(strlen(path) + 1 + strlen(mid_dir.current_file->file_name)+1); - memcpy(str, path, strlen(path)); - memcpy(str+strlen(path)+1, mid_dir.file_list[i].file_name, strlen(mid_dir.file_list[i].file_name)+1); - str[strlen(path)] = '/'; + char *str = malloc(strlen(global_path) + 1 + strlen(mid_dir.file_list[i].file_name)+1); + memcpy(str, global_path, strlen(global_path)); + memcpy(str+strlen(global_path)+1, mid_dir.file_list[i].file_name, strlen(mid_dir.file_list[i].file_name)+1); + str[strlen(global_path)] = '/'; yank_files.list[j] = str; j++; } } } else { - /*this path is achieved if no file is explicitly selected by the user, thus we assume the user wants the currently hovered file*/ + /*this condition is achieved if no file is explicitly selected by the user, thus we assume the user wants the currently hovered file*/ yank_files.list = malloc(1 * sizeof(char*)); - char *str = malloc(strlen(path) + 1 + strlen(mid_dir.current_file->file_name)+1); - memcpy(str, path, strlen(path)); - memcpy(str+strlen(path)+1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1); - str[strlen(path)] = '/'; + char *str = malloc(strlen(global_path) + 1 + strlen(mid_dir.current_file->file_name)+1); + memcpy(str, global_path, strlen(global_path)); + memcpy(str+strlen(global_path)+1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1); + str[strlen(global_path)] = '/'; *yank_files.list = str; yank_files.count = 1; } - /*free(path);*/ - status |= (STATUS_RUN_BACKEND); }