[PATCH] Avoid unnecessary/leaky use of strdup.

Jim Meyering meyering at redhat.com
Tue Mar 4 05:19:45 PST 2008


* polkit-grant-helper.c (main): Move the declaration of "buf"
to the outer scope and use a pointer into it, instead.

Signed-off-by: Jim Meyering <meyering at redhat.com>
---
 src/polkit-grant/polkit-grant-helper.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/polkit-grant/polkit-grant-helper.c b/src/polkit-grant/polkit-grant-helper.c
index fbf6769..b0f59f8 100644
--- a/src/polkit-grant/polkit-grant-helper.c
+++ b/src/polkit-grant/polkit-grant-helper.c
@@ -555,6 +555,7 @@ main (int argc, char *argv[])
         uid_t caller_uid;
         PolKitSession *session;
         gboolean empty_conversation;
+        char buf[256];

         ret = 3;

@@ -708,7 +709,6 @@ main (int argc, char *argv[])
         /* wait for libpolkit-grant to tell us what user to use */
         if (admin_users != NULL) {
                 int n;
-                char buf[256];

 #ifdef PGH_DEBUG
                 fprintf (stderr, "waiting for admin user name...\n");
@@ -726,7 +726,7 @@ main (int argc, char *argv[])
                         goto out;
                 }

-                user_to_auth = strdup (buf) + sizeof "POLKIT_GRANT_CALLER_SELECT_ADMIN_USER " - 1;
+                user_to_auth = buf + sizeof "POLKIT_GRANT_CALLER_SELECT_ADMIN_USER " - 1;
 #ifdef PGH_DEBUG
                 fprintf (stderr, "libpolkit-grant wants to auth as '%s'\n", user_to_auth);
 #endif /* PGH_DEBUG */
-- 
1.5.4.3.448.ga661


--=-=-=


--------------------------------------------------------------
Handle kit_strdup failure.
* tools/polkit-policy-file-validate.c (validate_file):

--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
 filename=0005-Handle-kit_strdup-failure.patch



More information about the hal mailing list