Fix all memory leaks detected by valgrind
authorAlberto Mardegan <alberto.mardegan@canonical.com>
Thu, 29 Nov 2012 11:58:06 +0000 (13:58 +0200)
committerAlberto Mardegan <alberto.mardegan@canonical.com>
Thu, 29 Nov 2012 12:00:52 +0000 (14:00 +0200)
libsignon-glib/signon-auth-service.c
libsignon-glib/signon-auth-session.c
libsignon-glib/signon-identity.c
tests/check_signon.c

index 444227b57809ecb5eb06761b7f650a35d5874e27..3c8db4371728675383539f2cdbc0da4cb72466c4 100644 (file)
@@ -144,7 +144,7 @@ auth_query_methods_cb (GObject *object, GAsyncResult *res,
     (data->cb)
         (data->service, value, error, data->userdata);
 
-    g_free (value);
+    g_strfreev (value);
     if (error)
         g_error_free (error);
     g_slice_free (MethodCbData, data);
@@ -166,7 +166,7 @@ auth_query_mechanisms_cb (GObject *object, GAsyncResult *res,
     (data->cb)
         (data->service, data->method, value, error, data->userdata);
 
-    g_free (value);
+    g_strfreev (value);
     if (error)
         g_error_free (error);
     g_free (data->method);
index 488323ed0f3e19ac972083c6efe5b65e10cace16..c896ab59efa825df773196033c6a7d458687f95a 100644 (file)
@@ -530,6 +530,7 @@ auth_session_get_object_path_reply (GObject *object, GAsyncResult *res,
     }
 
     DEBUG ("Object path received: %s", object_path);
+    g_free (object_path);
     _signon_object_ready (self, auth_session_object_quark (), error);
     g_clear_error (&error);
 }
index cdf7dcafd70d9e61173eb5ed5be5597eb408591b..2e0989f45f5efa17551c87e6e696652ec7971656 100644 (file)
@@ -478,7 +478,7 @@ identity_new_cb (GObject *object, GAsyncResult *res,
 {
     SignonIdentity *identity = (SignonIdentity*)userdata;
     SsoAuthService *proxy = SSO_AUTH_SERVICE (object);
-    gchar *object_path;
+    gchar *object_path = NULL;
     GError *error = NULL;
 
     g_return_if_fail (identity != NULL);
@@ -490,6 +490,7 @@ identity_new_cb (GObject *object, GAsyncResult *res,
                                                         &error);
     SIGNON_RETURN_IF_CANCELLED (error);
     identity_registered (identity, object_path, NULL, error);
+    g_free (object_path);
 }
 
 static void
@@ -498,7 +499,7 @@ identity_new_from_db_cb (GObject *object, GAsyncResult *res,
 {
     SignonIdentity *identity = (SignonIdentity*)userdata;
     SsoAuthService *proxy = SSO_AUTH_SERVICE (object);
-    gchar *object_path;
+    gchar *object_path = NULL;
     GVariant *identity_data;
     GError *error = NULL;
 
@@ -512,6 +513,7 @@ identity_new_from_db_cb (GObject *object, GAsyncResult *res,
                                                &error);
     SIGNON_RETURN_IF_CANCELLED (error);
     identity_registered (identity, object_path, identity_data, error);
+    g_free (object_path);
 }
 
 static void
index 957db3d4c53b54505ba5eb05c1c03fc4084e1190..d67ffa1b4a44b5611139bc3fc1e03dcd80d928aa 100644 (file)
@@ -358,6 +358,8 @@ START_TEST(test_auth_session_query_mechanisms_nonexisting)
     g_main_loop_run (main_loop);
 
     g_free(patterns[0]);
+    g_free(patterns[1]);
+    g_free(patterns[2]);
     g_object_unref(idty);
 
     end_test ();
@@ -479,8 +481,7 @@ START_TEST(test_auth_session_process)
                                "mech1",
                                test_auth_session_process_cb,
                                sessionData);
-    if(!main_loop)
-        main_loop = g_main_loop_new (NULL, FALSE);
+    main_loop = g_main_loop_new (NULL, FALSE);
 
 
     g_main_loop_run (main_loop);
@@ -518,7 +519,7 @@ START_TEST(test_auth_session_process)
     g_free(passwordVa);
     g_free(passwordKey);
 
-
+    end_test ();
 }
 END_TEST
 
@@ -666,9 +667,6 @@ new_identity()
     GHashTable *methods;
     guint id = 0;
 
-    if (main_loop == NULL)
-        main_loop = g_main_loop_new (NULL, FALSE);
-
     identity = signon_identity_new(NULL, NULL);
     fail_unless (SIGNON_IS_IDENTITY (identity));
     methods = g_hash_table_new (g_str_hash, g_str_equal);
@@ -704,6 +702,8 @@ START_TEST(test_get_existing_identity)
     g_type_init ();
 
     g_debug("%s", G_STRFUNC);
+
+    main_loop = g_main_loop_new (NULL, FALSE);
     guint id = new_identity();
 
     fail_unless (id != 0);
@@ -715,7 +715,6 @@ START_TEST(test_get_existing_identity)
                  "Failed to initialize the Identity.");
 
     g_timeout_add (1000, identity_registered_cb, identity);
-    main_loop = g_main_loop_new (NULL, FALSE);
     g_main_loop_run (main_loop);
 
     end_test ();
@@ -785,6 +784,7 @@ START_TEST(test_store_credentials_identity)
     fail_unless (SIGNON_IS_IDENTITY (idty),
                  "Failed to initialize the Identity.");
 
+    main_loop = g_main_loop_new (NULL, FALSE);
     gint last_id = new_identity();
 
     GHashTable *methods = create_methods_hashtable();
@@ -803,7 +803,6 @@ START_TEST(test_store_credentials_identity)
     g_hash_table_destroy (methods);
 
     g_timeout_add (1000, test_quit_main_loop_cb, idty);
-    main_loop = g_main_loop_new (NULL, FALSE);
     g_main_loop_run (main_loop);
 
     g_object_unref(idty);
@@ -1218,6 +1217,8 @@ START_TEST(test_signout_identity)
 
     g_object_unref (idty);
     g_object_unref (idty2);
+
+    end_test ();
 }
 END_TEST
 
@@ -1255,6 +1256,8 @@ START_TEST(test_unregistered_identity)
 
     g_object_unref (idty);
     g_object_unref (idty2);
+
+    end_test ();
 }
 END_TEST
 
@@ -1368,8 +1371,10 @@ START_TEST(test_regression_unref)
                                  session_data,
                                  "mech1",
                                  test_regression_unref_process_cb,
-                                 g_strdup ("Hi there!"));
+                                 "Hi there!");
     g_main_loop_run (main_loop);
+
+    end_test ();
 }
 END_TEST