mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 06:56:00 +01:00
Fixed some memory issues
This commit is contained in:
parent
5803a7f00b
commit
3bcc7b28e6
1 changed files with 38 additions and 2 deletions
40
zathura.c
40
zathura.c
|
@ -276,6 +276,7 @@ struct
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
GFileMonitor* monitor;
|
GFileMonitor* monitor;
|
||||||
|
GFile* file;
|
||||||
} FileMonitor;
|
} FileMonitor;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|
@ -570,7 +571,7 @@ init_keylist()
|
||||||
void
|
void
|
||||||
init_settings()
|
init_settings()
|
||||||
{
|
{
|
||||||
Zathura.State.filename = (char*) default_text;
|
Zathura.State.filename = g_strdup((char*) default_text);
|
||||||
Zathura.Global.adjust_mode = adjust_open;
|
Zathura.Global.adjust_mode = adjust_open;
|
||||||
|
|
||||||
gtk_window_set_default_size(GTK_WINDOW(Zathura.UI.window), default_width, default_height);
|
gtk_window_set_default_size(GTK_WINDOW(Zathura.UI.window), default_width, default_height);
|
||||||
|
@ -607,6 +608,7 @@ init_zathura()
|
||||||
Zathura.Search.draw = FALSE;
|
Zathura.Search.draw = FALSE;
|
||||||
|
|
||||||
Zathura.FileMonitor.monitor = NULL;
|
Zathura.FileMonitor.monitor = NULL;
|
||||||
|
Zathura.FileMonitor.file = NULL;
|
||||||
|
|
||||||
/* window */
|
/* window */
|
||||||
if(Zathura.UI.embed)
|
if(Zathura.UI.embed)
|
||||||
|
@ -952,6 +954,9 @@ close_file(gboolean keep_monitor)
|
||||||
{
|
{
|
||||||
Page* current_page = Zathura.PDF.pages[i];
|
Page* current_page = Zathura.PDF.pages[i];
|
||||||
g_object_unref(current_page->page);
|
g_object_unref(current_page->page);
|
||||||
|
if(current_page->label)
|
||||||
|
g_free(current_page->label);
|
||||||
|
free(current_page);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* save bookmarks */
|
/* save bookmarks */
|
||||||
|
@ -982,6 +987,12 @@ close_file(gboolean keep_monitor)
|
||||||
{
|
{
|
||||||
g_object_unref(Zathura.FileMonitor.monitor);
|
g_object_unref(Zathura.FileMonitor.monitor);
|
||||||
Zathura.FileMonitor.monitor = NULL;
|
Zathura.FileMonitor.monitor = NULL;
|
||||||
|
|
||||||
|
if(Zathura.FileMonitor.file)
|
||||||
|
{
|
||||||
|
g_object_unref(Zathura.FileMonitor.file);
|
||||||
|
Zathura.FileMonitor.file = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reset values */
|
/* reset values */
|
||||||
|
@ -991,10 +1002,15 @@ close_file(gboolean keep_monitor)
|
||||||
gtk_window_set_title(GTK_WINDOW(Zathura.UI.window), "zathura");
|
gtk_window_set_title(GTK_WINDOW(Zathura.UI.window), "zathura");
|
||||||
|
|
||||||
Zathura.State.pages = g_strdup_printf("");
|
Zathura.State.pages = g_strdup_printf("");
|
||||||
Zathura.State.filename = (char*) default_text;;
|
if(Zathura.State.filename)
|
||||||
|
g_free(Zathura.State.filename);
|
||||||
|
Zathura.State.filename = g_strdup((char*) default_text);
|
||||||
|
|
||||||
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
|
g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock));
|
||||||
Zathura.PDF.document = NULL;
|
Zathura.PDF.document = NULL;
|
||||||
|
if(Zathura.PDF.file)
|
||||||
|
free(Zathura.PDF.file);
|
||||||
|
|
||||||
if(!keep_monitor)
|
if(!keep_monitor)
|
||||||
{
|
{
|
||||||
Zathura.PDF.file = NULL;
|
Zathura.PDF.file = NULL;
|
||||||
|
@ -1131,6 +1147,8 @@ open_file(char* path, char* password)
|
||||||
{
|
{
|
||||||
char* home_path = getenv("HOME");
|
char* home_path = getenv("HOME");
|
||||||
int file_len = strlen(home_path) + strlen(path) - 1;
|
int file_len = strlen(home_path) + strlen(path) - 1;
|
||||||
|
if(file)
|
||||||
|
free(file);
|
||||||
file = malloc(file_len);
|
file = malloc(file_len);
|
||||||
if(!file)
|
if(!file)
|
||||||
out_of_memory();
|
out_of_memory();
|
||||||
|
@ -1157,6 +1175,8 @@ open_file(char* path, char* password)
|
||||||
char* file_uri = g_filename_to_uri(file, NULL, &error);
|
char* file_uri = g_filename_to_uri(file, NULL, &error);
|
||||||
if (!file_uri)
|
if (!file_uri)
|
||||||
{
|
{
|
||||||
|
if(file)
|
||||||
|
free(file);
|
||||||
char* message = g_strdup_printf("Can not open file: %s", error->message);
|
char* message = g_strdup_printf("Can not open file: %s", error->message);
|
||||||
notify(ERROR, message);
|
notify(ERROR, message);
|
||||||
g_free(message);
|
g_free(message);
|
||||||
|
@ -1206,6 +1226,7 @@ open_file(char* path, char* password)
|
||||||
Zathura.FileMonitor.monitor = g_file_monitor_file(file, G_FILE_MONITOR_NONE, NULL, NULL);
|
Zathura.FileMonitor.monitor = g_file_monitor_file(file, G_FILE_MONITOR_NONE, NULL, NULL);
|
||||||
if(Zathura.FileMonitor.monitor)
|
if(Zathura.FileMonitor.monitor)
|
||||||
g_signal_connect(G_OBJECT(Zathura.FileMonitor.monitor), "changed", G_CALLBACK(cb_watch_file), NULL);
|
g_signal_connect(G_OBJECT(Zathura.FileMonitor.monitor), "changed", G_CALLBACK(cb_watch_file), NULL);
|
||||||
|
Zathura.FileMonitor.file = file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1217,6 +1238,8 @@ open_file(char* path, char* password)
|
||||||
Zathura.PDF.file = file;
|
Zathura.PDF.file = file;
|
||||||
Zathura.PDF.scale = 100;
|
Zathura.PDF.scale = 100;
|
||||||
Zathura.PDF.rotate = 0;
|
Zathura.PDF.rotate = 0;
|
||||||
|
if(Zathura.State.filename)
|
||||||
|
g_free(Zathura.State.filename);
|
||||||
Zathura.State.filename = g_markup_escape_text(file, -1);
|
Zathura.State.filename = g_markup_escape_text(file, -1);
|
||||||
Zathura.PDF.pages = malloc(Zathura.PDF.number_of_pages * sizeof(Page*));
|
Zathura.PDF.pages = malloc(Zathura.PDF.number_of_pages * sizeof(Page*));
|
||||||
|
|
||||||
|
@ -1285,6 +1308,8 @@ open_file(char* path, char* password)
|
||||||
Zathura.Bookmarks.number_of_bookmarks++;
|
Zathura.Bookmarks.number_of_bookmarks++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_strfreev(keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set window title */
|
/* set window title */
|
||||||
|
@ -1369,7 +1394,12 @@ read_configuration()
|
||||||
cmd_set(length - 1, tokens + 1);
|
cmd_set(length - 1, tokens + 1);
|
||||||
else if(!strcmp(tokens[0], "map"))
|
else if(!strcmp(tokens[0], "map"))
|
||||||
cmd_map(length - 1, tokens + 1);
|
cmd_map(length - 1, tokens + 1);
|
||||||
|
|
||||||
|
g_strfreev(tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_strfreev(lines);
|
||||||
|
g_free(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3656,6 +3686,8 @@ cb_destroy(GtkWidget* widget, gpointer data)
|
||||||
/* inotify */
|
/* inotify */
|
||||||
if(Zathura.FileMonitor.monitor)
|
if(Zathura.FileMonitor.monitor)
|
||||||
g_object_unref(Zathura.FileMonitor.monitor);
|
g_object_unref(Zathura.FileMonitor.monitor);
|
||||||
|
if(Zathura.FileMonitor.file)
|
||||||
|
g_object_unref(Zathura.FileMonitor.file);
|
||||||
|
|
||||||
g_list_free(Zathura.Global.history);
|
g_list_free(Zathura.Global.history);
|
||||||
|
|
||||||
|
@ -3669,6 +3701,9 @@ cb_destroy(GtkWidget* widget, gpointer data)
|
||||||
sc = ne;
|
sc = ne;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Zathura.State.filename)
|
||||||
|
g_free(Zathura.State.filename);
|
||||||
|
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -4070,6 +4105,7 @@ cb_view_button_release(GtkWidget* widget, GdkEventButton* event, gpointer data)
|
||||||
cairo_rectangle(cairo, rectangle.x1 - offset_x, rectangle.y1 - offset_y,
|
cairo_rectangle(cairo, rectangle.x1 - offset_x, rectangle.y1 - offset_y,
|
||||||
(rectangle.x2 - rectangle.x1), (rectangle.y2 - rectangle.y1));
|
(rectangle.x2 - rectangle.x1), (rectangle.y2 - rectangle.y1));
|
||||||
cairo_fill(cairo);
|
cairo_fill(cairo);
|
||||||
|
cairo_destroy(cairo);
|
||||||
gtk_widget_queue_draw(Zathura.UI.drawing_area);
|
gtk_widget_queue_draw(Zathura.UI.drawing_area);
|
||||||
|
|
||||||
/* resize selection rectangle to document page */
|
/* resize selection rectangle to document page */
|
||||||
|
|
Loading…
Reference in a new issue