Description: Fix several memory leaks.
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1000364
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=723745
Applied-Upstream: http://cgit.freedesktop.org/accountsservice/commit/?id=71a683f71d6
---
 src/daemon.c |   16 +++++++++-------
 src/user.c   |    5 +++++
 2 files changed, 14 insertions(+), 7 deletions(-)

--- accountsservice.orig/src/user.c
+++ accountsservice/src/user.c
@@ -1828,6 +1828,9 @@ user_finalize (GObject *object)
         g_free (user->location);
         g_free (user->password_hint);
 
+        if (user->login_history)
+                g_variant_unref (user->login_history);
+
         if (G_OBJECT_CLASS (user_parent_class)->finalize)
                 (*G_OBJECT_CLASS (user_parent_class)->finalize) (object);
 }
@@ -1860,6 +1863,8 @@ user_set_property (GObject      *object,
                 user->login_time = g_value_get_int64 (value);
                 break;
         case PROP_LOGIN_HISTORY:
+                if (user->login_history)
+                        g_variant_unref (user->login_history);
                 user->login_history = g_variant_ref (g_value_get_variant (value));
                 break;
         case PROP_AUTOMATIC_LOGIN:
--- accountsservice.orig/src/daemon.c
+++ accountsservice/src/daemon.c
@@ -207,6 +207,13 @@ typedef struct {
         GHashTable *logout_hash;
 } WTmpGeneratorState;
 
+static void
+user_previous_login_free (UserPreviousLogin *previous_login)
+{
+        g_free (previous_login->id);
+        g_free (previous_login);
+}
+
 static struct passwd *
 entry_generator_wtmp (GHashTable *users,
                       gpointer   *state)
@@ -316,11 +323,7 @@ entry_generator_wtmp (GHashTable *users,
 
                 user = g_hash_table_lookup (users, key);
                 if (user == NULL) {
-                        for (l = accounting->previous_logins; l != NULL; l = l->next) {
-                                previous_login = l->data;
-                                g_free (previous_login->id);
-                        }
-                        g_list_free (accounting->previous_logins);
+                        g_list_free_full (accounting->previous_logins, (GDestroyNotify) user_previous_login_free);
                         continue;
                 }
 
@@ -335,11 +338,10 @@ entry_generator_wtmp (GHashTable *users,
                         g_variant_builder_add (builder2, "{sv}", "type", g_variant_new_string (previous_login->id));
                         g_variant_builder_add (builder, "(xxa{sv})", previous_login->login_time, previous_login->logout_time, builder2);
                         g_variant_builder_unref (builder2);
-                        g_free (previous_login->id);
                 }
                 g_object_set (user, "login-history", g_variant_new ("a(xxa{sv})", builder), NULL);
                 g_variant_builder_unref (builder);
-                g_list_free (accounting->previous_logins);
+                g_list_free_full (accounting->previous_logins, (GDestroyNotify) user_previous_login_free);
 
                 user_changed (user);
         }
