From 228a6ec9691c7382a9794c79e34dbf1f5316528b Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Tue, 8 Apr 2008 15:42:46 -0400 Subject: [PATCH] don't leak the copied authorizations list on OOM Now the test suite passes again. --- src/kit/kit-list.c | 6 ++++-- src/polkit/polkit-authorization-db.c | 10 ++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/kit/kit-list.c b/src/kit/kit-list.c index b00ebfc..da030a3 100644 --- a/src/kit/kit-list.c +++ b/src/kit/kit-list.c @@ -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; diff --git a/src/polkit/polkit-authorization-db.c b/src/polkit/polkit-authorization-db.c index 39bd12c..f40f5fd 100644 --- a/src/polkit/polkit-authorization-db.c +++ b/src/polkit/polkit-authorization-db.c @@ -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); -- 2.7.4