fixed some stabillity issues and memory leaks
This commit is contained in:
@@ -167,7 +167,7 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
if (*dir_file_count > 9) {
|
if (*dir_file_count > 9) {
|
||||||
offset_front = (snprintf(NULL, 0, "%ld", *dir_file_count)) + 1;
|
offset_front = (snprintf(NULL, 0, "%ld", *dir_file_count)) + 1;
|
||||||
}
|
}
|
||||||
if (selected_file_current > (terminal_height/3)*2) {
|
if (selected_file_current > (terminal_height/3)*2 && *dir_file_count > terminal_height - 2) {
|
||||||
if (selected_file_current + (terminal_height/3) >= *dir_file_count) {
|
if (selected_file_current + (terminal_height/3) >= *dir_file_count) {
|
||||||
offset_vertical = *dir_file_count - terminal_height+2;
|
offset_vertical = *dir_file_count - terminal_height+2;
|
||||||
} else {
|
} else {
|
||||||
@@ -247,9 +247,9 @@ void print_dir(WINDOW *win, char print_info, unsigned long *dir_file_count, file
|
|||||||
}
|
}
|
||||||
|
|
||||||
mvwaddstr(win, i-offset_vertical, 0, bg);
|
mvwaddstr(win, i-offset_vertical, 0, bg);
|
||||||
mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, file_name, line_width-offset_front-is_selected-2);
|
|
||||||
if(print_info) {
|
if(print_info) {
|
||||||
mvwprintw(win, i-offset_vertical, 0, "%ld", i);
|
mvwprintw(win, i-offset_vertical, 0, "%ld", i);
|
||||||
|
mvwaddnstr(win, i-offset_vertical, offset_front+is_selected, file_name, line_width-offset_front-is_selected-2);
|
||||||
free(file_name);
|
free(file_name);
|
||||||
|
|
||||||
if (dir_content[i].file_type == FILE_TYPE_DIR || dir_content[i].file_type == FILE_TYPE_SYMLINK) {
|
if (dir_content[i].file_type == FILE_TYPE_DIR || dir_content[i].file_type == FILE_TYPE_SYMLINK) {
|
||||||
|
@@ -20,7 +20,7 @@ char* get_mimetype(char *path){
|
|||||||
cmd[cmd_len + path_len + 1] = '\0';
|
cmd[cmd_len + path_len + 1] = '\0';
|
||||||
|
|
||||||
FILE *cmd_open = popen(cmd, "r");
|
FILE *cmd_open = popen(cmd, "r");
|
||||||
char *line;
|
char *line = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
if (getline(&line, &size, cmd_open) != -1){
|
if (getline(&line, &size, cmd_open) != -1){
|
||||||
pclose(cmd_open);
|
pclose(cmd_open);
|
||||||
@@ -30,18 +30,18 @@ char* get_mimetype(char *path){
|
|||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
char* preview_file(file *file_current){
|
char* preview_file(char *file_name, unsigned long file_size){
|
||||||
/* this calls "file" on path */
|
/* this calls "file" on path */
|
||||||
|
|
||||||
char *file_buffer;
|
char *file_buffer;
|
||||||
|
|
||||||
|
|
||||||
char *mime = get_mimetype(file_current->file_name);
|
char *mime = get_mimetype(file_name);
|
||||||
|
|
||||||
if (strstr(mime, "text")) {
|
if (strstr(mime, "text")) {
|
||||||
file_buffer = text(file_current->file_name, &file_current->file_size);
|
file_buffer = text(file_name, &file_size);
|
||||||
} else {
|
} else {
|
||||||
file_buffer = generic(file_current->file_name);
|
file_buffer = generic(file_name);
|
||||||
}
|
}
|
||||||
free(mime);
|
free(mime);
|
||||||
return file_buffer;
|
return file_buffer;
|
||||||
@@ -63,7 +63,7 @@ char* generic(char *path){
|
|||||||
cmd = concat(cmd, "\"");
|
cmd = concat(cmd, "\"");
|
||||||
|
|
||||||
FILE *cmd_open = popen(cmd, "r");
|
FILE *cmd_open = popen(cmd, "r");
|
||||||
char *line;
|
char *line = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
if (getline(&line, &size, cmd_open) != -1) {
|
if (getline(&line, &size, cmd_open) != -1) {
|
||||||
pclose(cmd_open);
|
pclose(cmd_open);
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
#include "file_previews.c"
|
#include "file_previews.c"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
char* preview_file(file *file_current);
|
char* preview_file(char *file_name, unsigned long file_size);
|
||||||
char* get_mimetype(char *path);
|
char* get_mimetype(char *path);
|
||||||
|
47
threading.c
47
threading.c
@@ -30,8 +30,8 @@ char *top_buffer; /* current path */
|
|||||||
volatile file *file_current;
|
volatile file *file_current;
|
||||||
|
|
||||||
|
|
||||||
unsigned long rgt_file_count;
|
unsigned long rgt_file_count = 0;
|
||||||
unsigned long mid_file_count;
|
unsigned long mid_file_count = 0;
|
||||||
unsigned long lft_file_count;
|
unsigned long lft_file_count;
|
||||||
unsigned long top_width;
|
unsigned long top_width;
|
||||||
|
|
||||||
@@ -56,6 +56,10 @@ void *thread_mid(void *data){
|
|||||||
|
|
||||||
|
|
||||||
if (status & STATUS_RELOAD_DIRECTORY) {
|
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);
|
free(mid_content);
|
||||||
mid_file_count = get_dir_size(path);
|
mid_file_count = get_dir_size(path);
|
||||||
if (mid_file_count > 0) {
|
if (mid_file_count > 0) {
|
||||||
@@ -104,8 +108,9 @@ void *thread_mid(void *data){
|
|||||||
selected_file_last = selected_file_current;
|
selected_file_last = selected_file_current;
|
||||||
|
|
||||||
free(file_current->file_name);
|
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);
|
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_size = mid_content[selected_file_current].file_size;
|
||||||
file_current->file_type = mid_content[selected_file_current].file_type;
|
file_current->file_type = mid_content[selected_file_current].file_type;
|
||||||
file_current->color_pair = mid_content[selected_file_current].color_pair;
|
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);
|
pthread_mutex_lock(&mutex_selection);
|
||||||
free(rgt_content);
|
char *path = malloc(strlen(file_current->file_name) + 1);
|
||||||
rgt_content = malloc(sizeof(file));
|
strcpy(path, file_current->file_name);
|
||||||
rgt_content->file_name = malloc(strlen(file_current->file_name));
|
unsigned char file_current_type = file_current->file_type;
|
||||||
strcpy(rgt_content->file_name, file_current->file_name);
|
unsigned long file_current_size = file_current->file_size;
|
||||||
rgt_content->file_size = file_current->file_size;
|
char file_current_status = file_current->status;
|
||||||
rgt_content->file_type = file_current->file_type;
|
|
||||||
rgt_content->status = file_current->status;
|
|
||||||
pthread_mutex_unlock(&mutex_selection);
|
pthread_mutex_unlock(&mutex_selection);
|
||||||
|
|
||||||
if (rgt_content->file_type == FILE_TYPE_DIR || rgt_content->file_type == FILE_TYPE_SYMLINK) {
|
if (file_current_type == FILE_TYPE_DIR || file_current_type == FILE_TYPE_SYMLINK) {
|
||||||
char *path = malloc(strlen(rgt_content[0].file_name) + 1);
|
|
||||||
strcpy(path, rgt_content[0].file_name);
|
unsigned long i = 0;
|
||||||
|
for (i = 0; i < rgt_file_count; i++) {
|
||||||
|
free(rgt_content[i].file_name);
|
||||||
|
}
|
||||||
free(rgt_content);
|
free(rgt_content);
|
||||||
|
|
||||||
rgt_file_count = get_dir_size(path);
|
rgt_file_count = get_dir_size(path);
|
||||||
rgt_content = malloc(rgt_file_count * sizeof(file));
|
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);
|
get_dir_content(path, &rgt_file_count, rgt_content);
|
||||||
rgt_content[0].status &= ~FILE_STATUS_FILE_OPEN;
|
rgt_content[0].status &= ~FILE_STATUS_FILE_OPEN;
|
||||||
free(path);
|
|
||||||
|
|
||||||
free(rgt_buffer);
|
free(rgt_buffer);
|
||||||
rgt_buffer = malloc(sizeof(char));
|
rgt_buffer = malloc(sizeof(char));
|
||||||
rgt_buffer[0] = '\0';
|
rgt_buffer[0] = '\0';
|
||||||
} else {
|
} 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_file_count = 0;
|
||||||
|
rgt_content = malloc(sizeof(file));
|
||||||
|
|
||||||
free(rgt_buffer);
|
free(rgt_buffer);
|
||||||
if (rgt_content->status & FILE_STATUS_DIR_EMPTY) {
|
if (file_current_status & FILE_STATUS_DIR_EMPTY) {
|
||||||
rgt_buffer = "empty dir";
|
rgt_buffer = "empty dir";
|
||||||
} else {
|
} else {
|
||||||
rgt_content->file_type = FILE_TYPE_OPEN_FILE;
|
rgt_content->file_type = FILE_TYPE_OPEN_FILE;
|
||||||
rgt_content->status = FILE_STATUS_HOVER;
|
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_mutex_unlock(&mutex_rgt);
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
|
Reference in New Issue
Block a user