fixed some stabillity issues and memory leaks
This commit is contained in:
47
threading.c
47
threading.c
@@ -30,8 +30,8 @@ char *top_buffer; /* current path */
|
||||
volatile file *file_current;
|
||||
|
||||
|
||||
unsigned long rgt_file_count;
|
||||
unsigned long mid_file_count;
|
||||
unsigned long rgt_file_count = 0;
|
||||
unsigned long mid_file_count = 0;
|
||||
unsigned long lft_file_count;
|
||||
unsigned long top_width;
|
||||
|
||||
@@ -56,6 +56,10 @@ void *thread_mid(void *data){
|
||||
|
||||
|
||||
if (status & STATUS_RELOAD_DIRECTORY) {
|
||||
unsigned long i = 0;
|
||||
for (i = 0; i < mid_file_count; i++) {
|
||||
free(mid_content[i].file_name);
|
||||
}
|
||||
free(mid_content);
|
||||
mid_file_count = get_dir_size(path);
|
||||
if (mid_file_count > 0) {
|
||||
@@ -104,8 +108,9 @@ void *thread_mid(void *data){
|
||||
selected_file_last = selected_file_current;
|
||||
|
||||
free(file_current->file_name);
|
||||
file_current->file_name = malloc(strlen(mid_content[selected_file_current].file_name));
|
||||
file_current->file_name = malloc(strlen(mid_content[selected_file_current].file_name)+1);
|
||||
strcpy(file_current->file_name, mid_content[selected_file_current].file_name);
|
||||
file_current->file_name[strlen(mid_content[selected_file_current].file_name)] = '\0';
|
||||
file_current->file_size = mid_content[selected_file_current].file_size;
|
||||
file_current->file_type = mid_content[selected_file_current].file_type;
|
||||
file_current->color_pair = mid_content[selected_file_current].color_pair;
|
||||
@@ -167,42 +172,50 @@ void *thread_rgt(void *data){
|
||||
|
||||
|
||||
pthread_mutex_lock(&mutex_selection);
|
||||
free(rgt_content);
|
||||
rgt_content = malloc(sizeof(file));
|
||||
rgt_content->file_name = malloc(strlen(file_current->file_name));
|
||||
strcpy(rgt_content->file_name, file_current->file_name);
|
||||
rgt_content->file_size = file_current->file_size;
|
||||
rgt_content->file_type = file_current->file_type;
|
||||
rgt_content->status = file_current->status;
|
||||
char *path = malloc(strlen(file_current->file_name) + 1);
|
||||
strcpy(path, file_current->file_name);
|
||||
unsigned char file_current_type = file_current->file_type;
|
||||
unsigned long file_current_size = file_current->file_size;
|
||||
char file_current_status = file_current->status;
|
||||
pthread_mutex_unlock(&mutex_selection);
|
||||
|
||||
if (rgt_content->file_type == FILE_TYPE_DIR || rgt_content->file_type == FILE_TYPE_SYMLINK) {
|
||||
char *path = malloc(strlen(rgt_content[0].file_name) + 1);
|
||||
strcpy(path, rgt_content[0].file_name);
|
||||
if (file_current_type == FILE_TYPE_DIR || file_current_type == FILE_TYPE_SYMLINK) {
|
||||
|
||||
unsigned long i = 0;
|
||||
for (i = 0; i < rgt_file_count; i++) {
|
||||
free(rgt_content[i].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));
|
||||
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(path);
|
||||
|
||||
free(rgt_buffer);
|
||||
rgt_buffer = malloc(sizeof(char));
|
||||
rgt_buffer[0] = '\0';
|
||||
} else {
|
||||
|
||||
unsigned long i = 0;
|
||||
for (i = 0; i < rgt_file_count; i++) {
|
||||
free(rgt_content[i].file_name);
|
||||
}
|
||||
free(rgt_content);
|
||||
rgt_file_count = 0;
|
||||
rgt_content = malloc(sizeof(file));
|
||||
|
||||
free(rgt_buffer);
|
||||
if (rgt_content->status & FILE_STATUS_DIR_EMPTY) {
|
||||
if (file_current_status & FILE_STATUS_DIR_EMPTY) {
|
||||
rgt_buffer = "empty dir";
|
||||
} else {
|
||||
rgt_content->file_type = FILE_TYPE_OPEN_FILE;
|
||||
rgt_content->status = FILE_STATUS_HOVER;
|
||||
rgt_buffer = preview_file(rgt_content);
|
||||
rgt_buffer = preview_file(path, file_current_size);
|
||||
}
|
||||
}
|
||||
free(path);
|
||||
|
||||
pthread_mutex_unlock(&mutex_rgt);
|
||||
pthread_exit(0);
|
||||
|
Reference in New Issue
Block a user