[gnome-control-center] users: Fix life-cycle issues
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] users: Fix life-cycle issues
- Date: Fri, 26 Aug 2011 03:46:11 +0000 (UTC)
commit f56f4a503da86b15809aa2b98f2fd7ee0a9605d5
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Aug 25 23:43:48 2011 -0400
users: Fix life-cycle issues
We were leaking various references, leading to failures to populate
the list upon reloading, or to segfaults. With this commit, all
created user objects, as well as the user-manager object are
finalized when the panel is unloaded.
panels/user-accounts/um-user-manager.c | 43 +++++++++++++++++++++----------
panels/user-accounts/um-user-manager.h | 1 -
panels/user-accounts/um-user-panel.c | 32 +++++++++++++++++------
panels/user-accounts/um-user.c | 2 +
4 files changed, 55 insertions(+), 23 deletions(-)
---
diff --git a/panels/user-accounts/um-user-manager.c b/panels/user-accounts/um-user-manager.c
index 442809a..54a0903 100644
--- a/panels/user-accounts/um-user-manager.c
+++ b/panels/user-accounts/um-user-manager.c
@@ -115,19 +115,15 @@ remove_user_from_dupe_ring (UmUserManager *manager,
GList *dupes;
UmUser *dup;
- um_user_show_short_display_name (user);
-
+ dup = NULL;
dupes = g_object_get_data (G_OBJECT (user), "dupes");
- if (dupes == NULL) {
- return;
+ if (!dupes) {
+ goto out;
}
if (dupes->next == dupes->prev) {
dup = dupes->next->data;
- um_user_show_short_display_name (dup);
- g_signal_emit (manager, signals[USER_CHANGED], 0, dup);
-
g_list_free_1 (dupes->next);
g_object_set_data (G_OBJECT (dup), "dupes", NULL);
}
@@ -138,6 +134,14 @@ remove_user_from_dupe_ring (UmUserManager *manager,
g_list_free_1 (dupes);
g_object_set_data (G_OBJECT (user), "dupes", NULL);
+
+out:
+ if (dup) {
+ um_user_show_short_display_name (dup);
+ g_signal_emit (manager, signals[USER_CHANGED], 0, dup);
+ }
+ um_user_show_short_display_name (user);
+ g_signal_emit (manager, signals[USER_CHANGED], 0, user);
}
static gboolean
@@ -163,16 +167,15 @@ add_user_to_dupe_ring (UmUserManager *manager,
return;
}
- um_user_show_full_display_name (user);
-
dupes = g_object_get_data (G_OBJECT (dup), "dupes");
if (!dupes) {
- um_user_show_full_display_name (dup);
- g_signal_emit (manager, signals[USER_CHANGED], 0, dup);
dupes = g_list_append (NULL, dup);
g_object_set_data (G_OBJECT (dup), "dupes", dupes);
dupes->next = dupes->prev = dupes;
}
+ else {
+ dup = NULL;
+ }
l = g_list_append (NULL, user);
g_object_set_data (G_OBJECT (user), "dupes", l);
@@ -180,6 +183,13 @@ add_user_to_dupe_ring (UmUserManager *manager,
dupes->prev->next = l;
l->next = dupes;
dupes->prev = l;
+
+ if (dup) {
+ um_user_show_full_display_name (dup);
+ g_signal_emit (manager, signals[USER_CHANGED], 0, dup);
+ }
+ um_user_show_full_display_name (user);
+ g_signal_emit (manager, signals[USER_CHANGED], 0, user);
}
static void
@@ -295,6 +305,7 @@ static void
um_user_manager_init (UmUserManager *manager)
{
GError *error = NULL;
+ DBusGConnection *bus;
manager->user_by_object_path = g_hash_table_new_full (g_str_hash,
g_str_equal,
@@ -305,14 +316,14 @@ um_user_manager_init (UmUserManager *manager)
g_free,
g_object_unref);
- manager->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (manager->bus == NULL) {
+ bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (bus == NULL) {
g_warning ("Couldn't connect to system bus: %s", error->message);
g_error_free (error);
goto error;
}
- manager->proxy = dbus_g_proxy_new_for_name (manager->bus,
+ manager->proxy = dbus_g_proxy_new_for_name (bus,
"org.freedesktop.Accounts",
"/org/freedesktop/Accounts",
"org.freedesktop.Accounts");
@@ -359,6 +370,8 @@ um_user_manager_finalize (GObject *object)
g_hash_table_destroy (manager->user_by_object_path);
g_hash_table_destroy (manager->user_by_name);
+ g_object_unref (manager->proxy);
+
G_OBJECT_CLASS (um_user_manager_parent_class)->finalize (object);
}
@@ -447,6 +460,7 @@ create_user_done (DBusGProxy *proxy,
}
data->callback (G_OBJECT (data->manager), G_ASYNC_RESULT (res), data->data);
+ g_object_unref (res);
}
gboolean
@@ -538,6 +552,7 @@ delete_user_done (DBusGProxy *proxy,
}
data->callback (G_OBJECT (data->manager), G_ASYNC_RESULT (res), data->data);
+ g_object_unref (res);
}
gboolean
diff --git a/panels/user-accounts/um-user-manager.h b/panels/user-accounts/um-user-manager.h
index b051a88..2999014 100644
--- a/panels/user-accounts/um-user-manager.h
+++ b/panels/user-accounts/um-user-manager.h
@@ -40,7 +40,6 @@ typedef struct
{
GObject parent;
- DBusGConnection *bus;
DBusGProxy *proxy;
GHashTable *user_by_object_path;
diff --git a/panels/user-accounts/um-user-panel.c b/panels/user-accounts/um-user-panel.c
index 42227cb..65a8abb 100644
--- a/panels/user-accounts/um-user-panel.c
+++ b/panels/user-accounts/um-user-panel.c
@@ -322,8 +322,11 @@ select_created_user (UmUser *user, UmUserPanelPrivate *d)
gtk_tree_view_scroll_to_cell (tv, path, NULL, FALSE, 0.0, 0.0);
gtk_tree_selection_select_path (selection, path);
gtk_tree_path_free (path);
+ g_object_unref (current);
break;
}
+ if (current)
+ g_object_unref (current);
} while (gtk_tree_model_iter_next (model, &iter));
}
@@ -458,6 +461,7 @@ delete_user (GtkButton *button, UmUserPanelPrivate *d)
gtk_window_present (GTK_WINDOW (dialog));
+ g_object_unref (user);
}
static const gchar *
@@ -634,10 +638,11 @@ change_name_done (GtkWidget *entry,
user = get_selected_user (d);
text = cc_editable_entry_get_text (CC_EDITABLE_ENTRY (entry));
-
if (g_strcmp0 (text, um_user_get_real_name (user)) != 0) {
um_user_set_real_name (user, text);
}
+
+ g_object_unref (user);
}
static void
@@ -650,6 +655,7 @@ account_type_changed (UmEditableCombo *combo,
gint account_type;
user = get_selected_user (d);
+
model = um_editable_combo_get_model (combo);
um_editable_combo_get_active_iter (combo, &iter);
gtk_tree_model_get (model, &iter, 1, &account_type, -1);
@@ -657,6 +663,8 @@ account_type_changed (UmEditableCombo *combo,
if (account_type != um_user_get_account_type (user)) {
um_user_set_account_type (user, account_type);
}
+
+ g_object_unref (user);
}
static void
@@ -671,6 +679,7 @@ language_response (GtkDialog *dialog,
GtkTreeIter iter;
user = get_selected_user (d);
+
combo = get_widget (d, "account-language-combo");
model = um_editable_combo_get_model (UM_EDITABLE_COMBO (combo));
@@ -689,6 +698,8 @@ language_response (GtkDialog *dialog,
gtk_widget_hide (GTK_WIDGET (dialog));
gtk_widget_set_sensitive (combo, TRUE);
+
+ g_object_unref (user);
}
static void
@@ -704,6 +715,7 @@ language_changed (UmEditableCombo *combo,
return;
user = get_selected_user (d);
+
model = um_editable_combo_get_model (combo);
gtk_tree_model_get (model, &iter, 0, &lang, -1);
@@ -712,14 +724,14 @@ language_changed (UmEditableCombo *combo,
um_user_set_language (user, lang);
}
g_free (lang);
- return;
+ goto out;
}
if (d->language_chooser) {
cc_language_chooser_clear_filter (d->language_chooser);
gtk_window_present (GTK_WINDOW (d->language_chooser));
gtk_widget_set_sensitive (GTK_WIDGET (combo), FALSE);
- return;
+ goto out;
}
d->language_chooser = cc_language_chooser_new (gtk_widget_get_toplevel (d->main_box), FALSE);
@@ -732,6 +744,9 @@ language_changed (UmEditableCombo *combo,
gdk_window_set_cursor (gtk_widget_get_window (gtk_widget_get_toplevel (d->main_box)), NULL);
gtk_window_present (GTK_WINDOW (d->language_chooser));
gtk_widget_set_sensitive (GTK_WIDGET (combo), FALSE);
+
+out:
+ g_object_unref (user);
}
static void
@@ -755,11 +770,13 @@ change_fingerprint (GtkButton *button, UmUserPanelPrivate *d)
UmUser *user;
user = get_selected_user (d);
+
g_assert (g_strcmp0 (g_get_user_name (), um_user_get_user_name (user)) == 0);
label = get_widget (d, "account-fingerprint-value-label");
label2 = get_widget (d, "account-fingerprint-button-label");
fingerprint_button_clicked (GTK_WINDOW (gtk_widget_get_toplevel (d->main_box)), label, label2, user);
+
g_object_unref (user);
}
@@ -988,6 +1005,8 @@ on_permission_changed (GPermission *permission,
}
um_password_dialog_set_privileged (d->password_dialog, is_authorized);
+
+ g_object_unref (user);
}
static gboolean
@@ -1063,10 +1082,7 @@ autologin_cell_data_func (GtkTreeViewColumn *tree_column,
{
gboolean is_autologin;
- gtk_tree_model_get (model,
- iter,
- AUTOLOGIN_COL, &is_autologin,
- -1);
+ gtk_tree_model_get (model, iter, AUTOLOGIN_COL, &is_autologin, -1);
if (is_autologin) {
g_object_set (cell, "icon-name", "emblem-default-symbolic", NULL);
@@ -1108,6 +1124,7 @@ setup_main_window (UmUserPanelPrivate *d)
gtk_tree_view_set_search_column (GTK_TREE_VIEW (userlist), USER_COL);
gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (userlist),
match_user, NULL, NULL);
+ g_object_unref (model);
g_signal_connect (d->um, "users-loaded", G_CALLBACK (users_loaded), d);
@@ -1300,7 +1317,6 @@ um_user_panel_dispose (GObject *object)
g_object_unref (priv->permission);
priv->permission = NULL;
}
-
G_OBJECT_CLASS (um_user_panel_parent_class)->dispose (object);
}
diff --git a/panels/user-accounts/um-user.c b/panels/user-accounts/um-user.c
index eda9252..f480108 100644
--- a/panels/user-accounts/um-user.c
+++ b/panels/user-accounts/um-user.c
@@ -242,6 +242,8 @@ um_user_finalize (GObject *object)
user = UM_USER (object);
+ g_free (user->display_name);
+
dbus_g_connection_unref (user->bus);
g_free (user->object_path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]