fixed some memory leaks
This commit is contained in:
51
threading.c
51
threading.c
@ -22,6 +22,8 @@ file *mid_content;
|
||||
file *lft_content;
|
||||
char *rgt_buffer; /* used for file previews, unlike rgt_content, which is used for directory previews */
|
||||
|
||||
file file_current;
|
||||
|
||||
char *top_content; /* current path */
|
||||
|
||||
unsigned long rgt_file_count;
|
||||
@ -70,6 +72,12 @@ void *thread_mid(void *data){
|
||||
selected_file_last = selected_file_current;
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
|
||||
file_current.file_name = malloc(mid_content[selected_file_current].file_name_width + 1);
|
||||
strcpy(file_current.file_name, mid_content[selected_file_current].file_name);
|
||||
file_current.file_name_width = mid_content[selected_file_current].file_name_width;
|
||||
file_current.file_size_bytes = mid_content[selected_file_current].file_size_bytes;
|
||||
file_current.file_type = mid_content[selected_file_current].file_type;
|
||||
|
||||
}
|
||||
free(path);
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
@ -77,6 +85,7 @@ void *thread_mid(void *data){
|
||||
}
|
||||
void *thread_lft(void *data){
|
||||
pthread_mutex_lock(&mutex_lft);
|
||||
/*{{{*/
|
||||
|
||||
|
||||
|
||||
@ -102,6 +111,7 @@ void *thread_lft(void *data){
|
||||
}
|
||||
free(path);
|
||||
pthread_mutex_unlock(&mutex_lft);
|
||||
/*}}}*/
|
||||
pthread_exit(NULL);
|
||||
|
||||
|
||||
@ -111,38 +121,34 @@ void *thread_rgt(void *data){
|
||||
|
||||
pthread_mutex_lock(&mutex_mid);
|
||||
/* TODO(2025-06-13T01:24:43) fix the occasional wrongly coppied path */
|
||||
char *path = malloc(mid_content[selected_file_current].file_name_width);
|
||||
strcpy(path, mid_content[selected_file_current].file_name);
|
||||
unsigned long name_len = strlen(mid_content[selected_file_current].file_name);
|
||||
unsigned long file_size = mid_content[selected_file_current].file_size_bytes;
|
||||
unsigned char file_type = mid_content[selected_file_current].file_type;
|
||||
free(rgt_content);
|
||||
rgt_content = malloc(sizeof(file));
|
||||
rgt_content[0].file_name = malloc(file_current.file_name_width + 1);
|
||||
strcpy(rgt_content[0].file_name, file_current.file_name);
|
||||
rgt_content[0].file_name_width = file_current.file_name_width;
|
||||
rgt_content[0].file_size_bytes = file_current.file_size_bytes;
|
||||
rgt_content[0].file_type = file_current.file_type;
|
||||
|
||||
pthread_mutex_unlock(&mutex_mid);
|
||||
|
||||
if (file_type == FILE_TYPE_DIR || file_type == FILE_TYPE_SYMLINK) {
|
||||
if (rgt_content[0].file_type == FILE_TYPE_DIR || rgt_content[0].file_type == FILE_TYPE_SYMLINK) {
|
||||
char *path = malloc(rgt_content[0].file_name_width + 1);
|
||||
strcpy(path, rgt_content[0].file_name);
|
||||
free(rgt_content);
|
||||
rgt_file_count = get_dir_size(path);
|
||||
rgt_content = malloc(rgt_file_count * sizeof(file));
|
||||
memset(rgt_content, ' ', rgt_file_count * sizeof(file));
|
||||
get_dir_content(path, &rgt_file_count, rgt_content);
|
||||
rgt_content[0].status &= ~FILE_STATUS_FILE_OPEN;
|
||||
} else if (file_type == FILE_TYPE_REGULAR || file_type == FILE_TYPE_EXEC) {
|
||||
free(rgt_content);
|
||||
free(path);
|
||||
} else if (rgt_content[0].file_type == FILE_TYPE_REGULAR) {
|
||||
|
||||
rgt_content = malloc(sizeof(file));
|
||||
rgt_content[0].file_name = malloc(name_len);
|
||||
rgt_content[0].file_name_width = name_len;
|
||||
rgt_content[0].file_size_bytes = file_size;
|
||||
/*memcpy(rgt_content[0].file_name, path, sizeof(path)/sizeof(char));*/
|
||||
strcpy(rgt_content[0].file_name, path);
|
||||
rgt_file_count = 1;
|
||||
|
||||
if (file_type != FILE_TYPE_EXEC) {
|
||||
rgt_content[0].file_type = FILE_TYPE_OPEN_FILE;
|
||||
rgt_content[0].status = FILE_STATUS_HOVER;
|
||||
free(rgt_buffer);
|
||||
rgt_buffer = preview_file(rgt_content[0].file_name, file_size);
|
||||
}
|
||||
rgt_content[0].file_type = FILE_TYPE_OPEN_FILE;
|
||||
rgt_content[0].status = FILE_STATUS_HOVER;
|
||||
free(rgt_buffer);
|
||||
rgt_buffer = preview_file(rgt_content[0].file_name, rgt_content[0].file_size_bytes);
|
||||
|
||||
}
|
||||
|
||||
@ -180,6 +186,11 @@ void threading_init(){
|
||||
top_content = malloc(sizeof(char));
|
||||
rgt_buffer = malloc(sizeof(char));
|
||||
|
||||
file_current.file_type = 0;
|
||||
file_current.file_size_bytes = 1;
|
||||
file_current.file_name_width = 1;
|
||||
file_current.file_name = "a";
|
||||
|
||||
pthread_mutex_init(&mutex_top, NULL);
|
||||
pthread_mutex_init(&mutex_mid, NULL);
|
||||
pthread_mutex_init(&mutex_lft, NULL);
|
||||
|
Reference in New Issue
Block a user