From 9bbc7eb9cbde19ff594ce5901fdf7bf1faac2874 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 15 Sep 2019 23:45:06 +0100 Subject: ensure pixbuf references are updated correctly to avoid leaks --- frontends/gtk/compat.c | 4 +++- frontends/gtk/gui.c | 4 ++-- frontends/gtk/tabs.c | 2 ++ frontends/gtk/toolbar.c | 42 +++++++++++++++++++++--------------------- frontends/gtk/window.c | 6 +++++- 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/frontends/gtk/compat.c b/frontends/gtk/compat.c index a8321d6d4..bd3f46ee5 100644 --- a/frontends/gtk/compat.c +++ b/frontends/gtk/compat.c @@ -635,7 +635,9 @@ void nsgtk_widget_set_margins(GtkWidget *widget, gint hmargin, gint vmargin) gtk_widget_set_margin_top(widget, vmargin); gtk_widget_set_margin_bottom(widget, vmargin); #else - gtk_misc_set_padding(GTK_MISC(widget), hmargin, vmargin); + if (GTK_IS_MISC(widget)) { + gtk_misc_set_padding(GTK_MISC(widget), hmargin, vmargin); + } #endif } diff --git a/frontends/gtk/gui.c b/frontends/gtk/gui.c index 205c5481b..a87ef7281 100644 --- a/frontends/gtk/gui.c +++ b/frontends/gtk/gui.c @@ -258,10 +258,10 @@ static nserror set_defaults(struct nsoption_s *defaults) */ static nserror nsgtk_add_named_icons_to_theme(void) { - #if GTK_CHECK_VERSION(3,14,0) +#if GTK_CHECK_VERSION(3,14,0) gtk_icon_theme_add_resource_path(gtk_icon_theme_get_default(), "/org/netsurf/icons"); - #else +#else GdkPixbuf *pixbuf; nserror res; diff --git a/frontends/gtk/tabs.c b/frontends/gtk/tabs.c index 04e90b935..6f4b22b0e 100644 --- a/frontends/gtk/tabs.c +++ b/frontends/gtk/tabs.c @@ -424,8 +424,10 @@ void nsgtk_tab_add(struct gui_window *gw, nsgtk_tab_add_page(notebook, tab_contents, background, title, icon_pixbuf); +#if 0 gtk_widget_grab_focus(GTK_WIDGET(nsgtk_scaffolding_urlbar( nsgtk_get_scaffold(gw)))); +#endif } diff --git a/frontends/gtk/toolbar.c b/frontends/gtk/toolbar.c index f7a18e749..8d6c09281 100644 --- a/frontends/gtk/toolbar.c +++ b/frontends/gtk/toolbar.c @@ -333,8 +333,7 @@ make_toolbar_item_websearch(bool sensitivity) res = search_web_get_provider_bitmap(&bitmap); if ((res == NSERROR_OK) && (bitmap != NULL)) { - pixbuf = nsgdk_pixbuf_get_from_surface(bitmap->surface, - 16, 16); + pixbuf = nsgdk_pixbuf_get_from_surface(bitmap->surface, 32, 32); } entry = nsgtk_entry_new(); @@ -347,6 +346,7 @@ make_toolbar_item_websearch(bool sensitivity) nsgtk_entry_set_icon_from_pixbuf(entry, GTK_ENTRY_ICON_PRIMARY, pixbuf); + g_object_unref(pixbuf); } else { nsgtk_entry_set_icon_from_icon_name(entry, GTK_ENTRY_ICON_PRIMARY, @@ -1284,7 +1284,6 @@ toolbar_customisation_create_toolbox(struct nsgtk_toolbar_customisation *tbc, static nserror customisation_toolbar_update(struct nsgtk_toolbar_customisation *tbc) { - GtkEntry *entry; nserror res; res = apply_user_button_customisation(&tbc->toolbar); @@ -1312,18 +1311,6 @@ customisation_toolbar_update(struct nsgtk_toolbar_customisation *tbc) return res; } - if (tbc->toolbar.items[URL_BAR_ITEM].location != INACTIVE_LOCATION) { - entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(tbc->toolbar.items[URL_BAR_ITEM].button))); - - gtk_widget_set_sensitive(GTK_WIDGET(entry), FALSE); - } - - if (tbc->toolbar.items[WEBSEARCH_ITEM].location != INACTIVE_LOCATION) { - entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(tbc->toolbar.items[WEBSEARCH_ITEM].button))); - - gtk_widget_set_sensitive(GTK_WIDGET(entry), FALSE); - } - return NSERROR_OK; } @@ -1365,6 +1352,22 @@ customisation_reset_clicked_cb(GtkWidget *widget, gpointer data) } +/** + * customisation container delete handler + */ +static gboolean +customisation_container_delete_cb(GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + struct nsgtk_toolbar_customisation *tbc; + tbc = (struct nsgtk_toolbar_customisation *)data; + + free(tbc); + + return FALSE; +} + /* * Toolbar button clicked handlers */ @@ -1482,16 +1485,13 @@ static gboolean cutomize_button_clicked_cb(GtkWidget *widget, gpointer data) G_CALLBACK(customisation_reset_clicked_cb), tbc); - /* close and cleanup on destroy signal */ -#if 0 - + /* close and cleanup on delete signal */ g_signal_connect(tbc->container, "delete-event", - G_CALLBACK(nsgtk_toolbar_delete), - g); + G_CALLBACK(customisation_container_delete_cb), + tbc); -#endif g_signal_connect(tbc->container, "drag-drop", G_CALLBACK(customisation_container_drag_drop_cb), diff --git a/frontends/gtk/window.c b/frontends/gtk/window.c index 9368d7003..647f15fcb 100644 --- a/frontends/gtk/window.c +++ b/frontends/gtk/window.c @@ -1408,13 +1408,17 @@ gui_search_web_provider_update(const char *name, struct bitmap *bitmap) GdkPixbuf *pixbuf = NULL; if (bitmap != NULL) { - pixbuf = nsgdk_pixbuf_get_from_surface(bitmap->surface, 16, 16); + pixbuf = nsgdk_pixbuf_get_from_surface(bitmap->surface, 32, 32); } for (gw = window_list; gw != NULL; gw = gw->next) { nsgtk_toolbar_set_websearch_image(gw->toolbar, pixbuf); } + if (pixbuf != NULL) { + g_object_unref(pixbuf); + } + return NSERROR_OK; } -- cgit v1.2.3