fix of copy_file

This commit is contained in:
nova
2026-06-18 21:54:51 +02:00
parent 60127a6b9b
commit f1b1400194
+9 -17
View File
@@ -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);
}