Blob Blame History Raw
From cfee906f39afa58d883e4fbed1888274c79c6e30 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Wed, 29 Jan 2014 10:29:04 -0500
Subject: [PATCH] user: fix memory leak in save_extra_data function

The save_extra_data function serializes a key file
assocated with the user to disk.

It fails to free the in memory buffer, however.

This commit fixes that.

see downstream bug https://bugzilla.redhat.com/show_bug.cgi?id=1003033
---
 src/user.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/user.c b/src/user.c
index 163d136..de30090 100644
--- a/src/user.c
+++ b/src/user.c
@@ -407,60 +407,61 @@ user_save_to_keyfile (User     *user,
 
         if (user->location)
                 g_key_file_set_string (keyfile, "User", "Location", user->location);
 
         if (user->password_hint)
                 g_key_file_set_string (keyfile, "User", "PasswordHint", user->password_hint);
 
         if (user->icon_file)
                 g_key_file_set_string (keyfile, "User", "Icon", user->icon_file);
 
         g_key_file_set_boolean (keyfile, "User", "SystemAccount", user->system_account);
 }
 
 static void
 save_extra_data (User *user)
 {
         gchar *filename;
         gchar *data;
         GError *error;
 
         user_save_to_keyfile (user, user->keyfile);
 
         error = NULL;
         data = g_key_file_to_data (user->keyfile, NULL, &error);
         if (error == NULL) {
                 filename = g_build_filename (USERDIR,
                                              user->user_name,
                                              NULL);
                 g_file_set_contents (filename, data, -1, &error);
                 g_free (filename);
+                g_free (data);
         }
         if (error) {
                 g_warning ("Saving data for user %s failed: %s",
                            user->user_name, error->message);
                 g_error_free (error);
         }
 }
 
 static void
 move_extra_data (const gchar *old_name,
                  const gchar *new_name)
 {
         gchar *old_filename;
         gchar *new_filename;
 
         old_filename = g_build_filename (USERDIR,
                                          old_name, NULL);
         new_filename = g_build_filename (USERDIR,
                                          new_name, NULL);
 
         g_rename (old_filename, new_filename);
 
         g_free (old_filename);
         g_free (new_filename);
 }
 
 static gchar *
 compute_object_path (User *user)
 {
         gchar *object_path;
-- 
1.8.4.2