From 749559f7f51369c2406f4a2730c9c064cf16f536 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 4 Mar 2012 01:02:14 +0100 Subject: [PATCH 1/3] Resolve memory leak in db_get_fileinfo --- database-plain.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/database-plain.c b/database-plain.c index 1099117..a36c031 100644 --- a/database-plain.c +++ b/database-plain.c @@ -260,11 +260,14 @@ zathura_db_get_fileinfo(zathura_database_t* db, const char* file, unsigned int* return false; } - *page = g_key_file_get_integer(db->history, file, KEY_PAGE, NULL); - *offset = g_key_file_get_integer(db->history, file, KEY_OFFSET, NULL); - *scale = strtod(g_key_file_get_string(db->history, file, KEY_SCALE, NULL), NULL); + *page = g_key_file_get_integer(db->history, file, KEY_PAGE, NULL); + *offset = g_key_file_get_integer(db->history, file, KEY_OFFSET, NULL); *rotation = g_key_file_get_integer(db->history, file, KEY_ROTATE, NULL); + char* scale_string = g_key_file_get_string(db->history, file, KEY_SCALE, NULL); + *scale = strtod(scale_string, NULL); + g_free(scale_string); + return true; } From 95239039e2730274075e86181f70beb352f11e82 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 4 Mar 2012 01:12:53 +0100 Subject: [PATCH 2/3] Free keys in db_load_bookmarks --- database-plain.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/database-plain.c b/database-plain.c index a36c031..6f8e55d 100644 --- a/database-plain.c +++ b/database-plain.c @@ -222,6 +222,8 @@ zathura_db_load_bookmarks(zathura_database_t* db, const char* file) girara_list_append(result, bookmark); } + g_strfreev(keys); + return result; } From 737fb386aebe8b2198588972d04ff06dc155b596 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 4 Mar 2012 01:30:27 +0100 Subject: [PATCH 3/3] Style update --- callbacks.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/callbacks.c b/callbacks.c index f5f6dcf..f4bbec7 100644 --- a/callbacks.c +++ b/callbacks.c @@ -32,8 +32,7 @@ cb_buffer_changed(girara_session_t* session) zathura_t* zathura = session->global.data; char* buffer = girara_buffer_get(session); - - if (buffer) { + if (buffer != NULL) { girara_statusbar_item_set_text(session, zathura->ui.statusbar.buffer, buffer); free(buffer); } else { @@ -45,7 +44,8 @@ void cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpointer data) { zathura_t* zathura = data; - if (!zathura || !zathura->document || !zathura->document->pages || !zathura->ui.page_widget) { + if (zathura == NULL || zathura->document == NULL || zathura->document->pages == NULL + || zathura->ui.page_widget == NULL) { return; } @@ -54,10 +54,10 @@ cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpoi GdkRectangle view_rect; /* get current adjustment values */ - view_rect.y = gtk_adjustment_get_value(view_vadjustment); + view_rect.y = gtk_adjustment_get_value(view_vadjustment); view_rect.height = gtk_adjustment_get_page_size(view_vadjustment); - view_rect.x = gtk_adjustment_get_value(view_hadjustment); - view_rect.width = gtk_adjustment_get_page_size(view_hadjustment); + view_rect.x = gtk_adjustment_get_value(view_hadjustment); + view_rect.width = gtk_adjustment_get_page_size(view_hadjustment); int page_padding = 1; girara_setting_get(zathura->ui.session, "page-padding", &page_padding); @@ -65,12 +65,11 @@ cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpoi GdkRectangle center; center.x = view_rect.x + (view_rect.width + 1) / 2; center.y = view_rect.y + (view_rect.height + 1) / 2; - center.height = center.width = 2*page_padding + 1; + center.height = center.width = (2 * page_padding) + 1; bool updated = false; /* find page that fits */ - for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) - { + for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) { zathura_page_t* page = zathura->document->pages[page_id]; page_offset_t offset; @@ -79,7 +78,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpoi GdkRectangle page_rect; page_rect.x = offset.x; page_rect.y = offset.y; - page_rect.width = page->width * zathura->document->scale; + page_rect.width = page->width * zathura->document->scale; page_rect.height = page->height * zathura->document->scale; if (gdk_rectangle_intersect(&view_rect, &page_rect, NULL) == TRUE) { @@ -133,8 +132,7 @@ cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path, g_object_get(tree_view, "model", &model, NULL); - if(gtk_tree_model_get_iter(model, &iter, path)) - { + if(gtk_tree_model_get_iter(model, &iter, path)) { zathura_index_element_t* index_element; gtk_tree_model_get(model, &iter, 2, &index_element, -1); @@ -238,10 +236,18 @@ static gboolean password_dialog(gpointer data) { zathura_password_dialog_info_t* dialog = data; + if (dialog != NULL) { - girara_dialog(dialog->zathura->ui.session, "Incorrect password. Enter password:", true, NULL, - (girara_callback_inputbar_activate_t) cb_password_dialog, dialog); + girara_dialog( + dialog->zathura->ui.session, + "Incorrect password. Enter password:", + true, + NULL, + (girara_callback_inputbar_activate_t) cb_password_dialog, + dialog + ); } + return FALSE; } @@ -309,7 +315,8 @@ cb_view_resized(GtkWidget* UNUSED(widget), GtkAllocation* allocation, zathura_t* if (width != allocation->width || height != allocation->height) { girara_argument_t argument = { zathura->document->adjust_mode, NULL }; sc_adjust_window(zathura->ui.session, &argument, NULL, 0); - width = allocation->width; + + width = allocation->width; height = allocation->height; }