From 4c21b0e6b34ca5a3b6a2984ea175582764e3f095 Mon Sep 17 00:00:00 2001 From: Mikhail Efremov Date: Wed, 20 Apr 2011 20:43:25 +0400 Subject: [PATCH] Fix more memory leaks. --- panel-plugin/xfce4-xkb-plugin.c | 14 ++++++---- panel-plugin/xkb-cairo.c | 1 + panel-plugin/xkb-config.c | 17 +++++++----- panel-plugin/xkb-settings-dialog.c | 49 +++++++++++++++++++++++++++--------- 4 files changed, 56 insertions(+), 25 deletions(-) diff --git a/panel-plugin/xfce4-xkb-plugin.c b/panel-plugin/xfce4-xkb-plugin.c index cf754f1..1b73610 100644 --- a/panel-plugin/xfce4-xkb-plugin.c +++ b/panel-plugin/xfce4-xkb-plugin.c @@ -367,20 +367,22 @@ xkb_initialize_menu (t_xkb *xkb) xkb->popup = gtk_menu_new (); for (i = 0; i < xkb_config_get_group_count (); i++) { + gchar *tmp_str; + imgfilename = xkb_util_get_flag_filename (xkb_config_get_group_name (i)); handle = rsvg_handle_new_from_file (imgfilename, NULL); + g_free (imgfilename); if (handle) { tmp = rsvg_handle_get_pixbuf (handle); } - menu_item = gtk_image_menu_item_new_with_label ( - xkb_util_get_layout_string ( - xkb_config_get_group_name (i), - xkb_config_get_variant (i) - ) - ); + tmp_str = xkb_util_get_layout_string (xkb_config_get_group_name (i), + xkb_config_get_variant (i)); + menu_item = gtk_image_menu_item_new_with_label (tmp_str); + g_free (tmp_str); + g_signal_connect (G_OBJECT (menu_item), "activate", G_CALLBACK (xkb_plugin_set_group), GINT_TO_POINTER (i)); diff --git a/panel-plugin/xkb-cairo.c b/panel-plugin/xkb-cairo.c index 8f5633f..ed9de23 100644 --- a/panel-plugin/xkb-cairo.c +++ b/panel-plugin/xkb-cairo.c @@ -85,6 +85,7 @@ xkb_cairo_draw_flag (cairo_t *cr, filename = xkb_util_get_flag_filename (group_name); handle = rsvg_handle_new_from_file (filename, NULL); + g_free (filename); if (!handle) { xkb_cairo_draw_label (cr, group_name, diff --git a/panel-plugin/xkb-config.c b/panel-plugin/xkb-config.c index 5151400..1fe15a3 100644 --- a/panel-plugin/xkb-config.c +++ b/panel-plugin/xkb-config.c @@ -228,6 +228,7 @@ void xkb_config_finalize () { xkb_config_free (); + g_free (config); gdk_window_remove_filter (NULL, (GdkFilterFunc) handle_xevent, NULL); @@ -272,7 +273,6 @@ xkb_config_update_settings (t_xkb_settings *settings) gchar **opt; gchar **prefix; - gchar *options; g_assert (config != NULL); g_assert (settings != NULL); @@ -291,17 +291,17 @@ xkb_config_update_settings (t_xkb_settings *settings) settings->kbd_config->model = g_strdup (config->config_rec->model); settings->kbd_config->layouts = g_strjoinv (",", config->config_rec->layouts); settings->kbd_config->variants = g_strjoinv (",", config->config_rec->variants); - options = g_strjoinv (",", config->config_rec->options); - if (strcmp ("", options) == 0) - { - options = NULL; - } } else { + gchar *options; + activate_settings = TRUE; + g_free (config->config_rec->model); config->config_rec->model = g_strdup (settings->kbd_config->model); + g_strfreev (config->config_rec->layouts); config->config_rec->layouts = g_strsplit_set (settings->kbd_config->layouts, ",", 0); + g_strfreev (config->config_rec->variants); config->config_rec->variants = g_strsplit_set (settings->kbd_config->variants, ",", 0); if (settings->kbd_config->toggle_option @@ -316,7 +316,9 @@ xkb_config_update_settings (t_xkb_settings *settings) options = g_strconcat (options, ",", settings->kbd_config->compose_key_position, NULL); g_free (tmp); } + g_strfreev (config->config_rec->options); config->config_rec->options = g_strsplit_set (options, ",", 0); + g_free (options); } /* select the first "grp" option and use it (should be fixed to support more options) */ @@ -338,8 +340,9 @@ xkb_config_update_settings (t_xkb_settings *settings) settings->kbd_config->compose_key_position = g_strdup (*opt); } opt++; + g_strfreev (prefix); } - + if (activate_settings && !settings->never_modify_config) xkl_config_rec_activate (config->config_rec, config->engine); diff --git a/panel-plugin/xkb-settings-dialog.c b/panel-plugin/xkb-settings-dialog.c index 53be11c..113f7e8 100644 --- a/panel-plugin/xkb-settings-dialog.c +++ b/panel-plugin/xkb-settings-dialog.c @@ -123,6 +123,8 @@ xkb_settings_fill_layout_tree_model_with_config (t_xkb *xkb) -1); layout_nb += 1; } + g_strfreev (layouts); + g_strfreev (variants); } static void @@ -209,6 +211,7 @@ xkb_settings_set_toggle_option_combo_default_value (t_xkb *xkb) { while (gtk_tree_model_iter_next(model, &iter)) { + g_free (id); gtk_tree_model_get (model, &iter, NOM, &id, -1); if (strcmp (id, config->toggle_option) == 0) @@ -248,6 +251,7 @@ xkb_settings_set_compose_key_position_combo_default_value (t_xkb *xkb) { while (gtk_tree_model_iter_next (model, &iter)) { + g_free (id); gtk_tree_model_get (model, &iter, NOM, &id, -1); if (strcmp (id, config->compose_key_position) == 0) @@ -276,6 +280,7 @@ xkb_settings_set_kbd_combo_default_value (t_xkb *xkb) { while (gtk_tree_model_iter_next(model, &iter)) { + g_free (id); gtk_tree_model_get (model, &iter, NOM, &id, -1); if (strcmp (id, config->model) == 0) @@ -344,7 +349,7 @@ xkb_settings_edit_layout (GtkWidget *widget, t_xkb *xkb) VARIANTS, strings[1], -1); xkb_settings_update_from_ui (xkb); - g_free(strings); + g_strfreev (strings); } g_free(c); xkb_settings_edit_layout_btn_show (GTK_TREE_VIEW (xkb->layout_tree_view), xkb); @@ -368,7 +373,7 @@ xkb_settings_add_layout (GtkWidget *widget, t_xkb *xkb) -1); xkb_settings_show_hide_layout_buttons (xkb); xkb_settings_update_from_ui (xkb); - g_free (strings); + g_strfreev (strings); } g_free (c); xkb_settings_edit_layout_btn_show (GTK_TREE_VIEW (xkb->layout_tree_view), xkb); @@ -794,10 +799,10 @@ xkb_settings_layout_dialog_run () selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); gchar *id; gchar *strings[2]; - + gchar *tmp; + gtk_tree_selection_get_selected (selection, &model, &iter); gtk_tree_model_get (model, &iter, AVAIL_LAYOUT_TREE_COL_ID, &id, -1); - path = gtk_tree_model_get_path (model, &iter); if (gtk_tree_path_get_depth (path) == 1) { @@ -809,13 +814,16 @@ xkb_settings_layout_dialog_run () strings[1] = id; gtk_tree_path_up(path); gtk_tree_model_get_iter(model, &iter, path); + g_free (id); gtk_tree_model_get (model, &iter, AVAIL_LAYOUT_TREE_COL_ID, &id, -1); strings[0] = id; } gtk_widget_destroy (dialog); - return g_strconcat(strings[0], ",", strings[1], NULL); - + gtk_tree_path_free (path); + tmp = g_strconcat(strings[0], ",", strings[1], NULL); + g_free (id); + return tmp; } gtk_widget_destroy (dialog); return NULL; @@ -834,6 +842,7 @@ xkb_settings_update_from_ui (t_xkb *xkb) if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (xkb->kbd_model_combo), &iter)) { gtk_tree_model_get (model, &iter, NOM, &kbdmodel, -1); + g_free (kbd_config->model); kbd_config->model = kbdmodel; } @@ -845,6 +854,7 @@ xkb_settings_update_from_ui (t_xkb *xkb) if (strcmp ("", toggle_option) == 0) kbd_config->toggle_option = NULL; else kbd_config->toggle_option = g_strdup (toggle_option); + g_free (toggle_option); } model = GTK_TREE_MODEL (xkb->compose_key_options_store); @@ -855,31 +865,46 @@ xkb_settings_update_from_ui (t_xkb *xkb) if (strcmp ("", compose_key_position) == 0) kbd_config->compose_key_position = NULL; else kbd_config->compose_key_position = g_strdup (compose_key_position); - + g_free (compose_key_position); } model = GTK_TREE_MODEL (xkb->layout_store); gtk_tree_model_get_iter_first (model, &iter); gtk_tree_model_get (model, &iter, DEFAULT_LAYOUT, &is_default, LAYOUTS, &layouts, VARIANTS, &variants, -1); if (is_default) xkb->settings->default_group = i; + + g_free (kbd_config->layouts); kbd_config->layouts = layouts; + + g_free (kbd_config->variants); if (variants != NULL) kbd_config->variants = variants; else - kbd_config->variants = ""; + kbd_config->variants = g_strdup (""); i = 1; while (gtk_tree_model_iter_next (model, &iter)) { + gchar *tmp; + gtk_tree_model_get (model, &iter, DEFAULT_LAYOUT, &is_default, LAYOUTS, &layouts, VARIANTS, &variants, -1); if (is_default) xkb->settings->default_group = i; i++; - kbd_config->layouts = g_strconcat(kbd_config->layouts, ",", layouts, NULL); + tmp = g_strconcat(kbd_config->layouts, ",", layouts, NULL); + g_free (kbd_config->layouts); + kbd_config->layouts = tmp; + g_free (layouts); + if (variants != NULL) - kbd_config->variants = g_strconcat(kbd_config->variants, ",", variants, NULL); - else - kbd_config->variants = g_strconcat(kbd_config->variants, ",", NULL); + { + tmp = g_strconcat(kbd_config->variants, ",", variants, NULL); + g_free (variants); + } else + tmp = g_strconcat(kbd_config->variants, ",", NULL); + + g_free (kbd_config->variants); + kbd_config->variants = tmp; } xkb_config_update_settings (xkb->settings); xkb_refresh_gui (xkb); -- 1.7.4.4