don't leak the copied authorizations list on OOM
authorDavid Zeuthen <davidz@redhat.com>
Tue, 8 Apr 2008 19:42:46 +0000 (15:42 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Tue, 8 Apr 2008 19:42:46 +0000 (15:42 -0400)
Now the test suite passes again.

src/kit/kit-list.c
src/polkit/polkit-authorization-db.c

index b00ebfc..da030a3 100644 (file)
@@ -93,14 +93,16 @@ KitList *
 kit_list_copy (KitList *list)
 {
         KitList *l;
+        KitList *l2;
         KitList *j;
 
         l = NULL;
         for (j = list; j != NULL; j = j->next) {
                 /* TODO: prepend, then reverse */
-                l = kit_list_append (l, j->data);
-                if (l == NULL)
+                l2 = kit_list_append (l, j->data);
+                if (l2 == NULL)
                         goto oom;
+                l = l2;
         }
 
         return l;
index 39bd12c..f40f5fd 100644 (file)
@@ -342,6 +342,8 @@ _authdb_get_auths_for_uid (PolKitAuthorizationDB *authdb,
                 goto out;
         }
 
+        //kit_warning ("standard_output='%s'", standard_output);
+
         if (standard_output != NULL) {
                 uid_t uid2;
                 len = strlen (standard_output);
@@ -472,8 +474,12 @@ _internal_foreach (PolKitAuthorizationDB       *authdb,
          * may disappear from under us due to revoke_if_one_shot...
          */
         auths_copy = kit_list_copy (auths);
-        if (auths_copy == NULL)
+        if (auths_copy == NULL) {
+                polkit_error_set_error (error,
+                                        POLKIT_ERROR_OUT_OF_MEMORY,
+                                        "No memory");
                 goto out;
+        }
         for (l = auths_copy; l != NULL; l = l->next)
                 polkit_authorization_ref ((PolKitAuthorization *) l->data);
 
@@ -1280,7 +1286,7 @@ _run_test (void)
                 //kit_warning ("%p: %d: %s: %s", 
                 //             error, 
                 //             polkit_error_get_error_code (error), 
-                //            polkit_error_get_error_name (error),
+                //             polkit_error_get_error_name (error),
                 //             polkit_error_get_error_message (error));
                 kit_assert (polkit_error_is_set (error) && 
                             polkit_error_get_error_code (error) == POLKIT_ERROR_OUT_OF_MEMORY);