]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: cleanup macros get{g,u}name
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 19 Feb 2019 22:48:06 +0000 (23:48 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 19 Feb 2019 22:50:25 +0000 (23:50 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c

index 7bdd794c7eda89ee30e67e428dce7ed7d6eebbb9..f089679bab4b5d1f8f537b417420fa9c0ce002be 100644 (file)
@@ -4597,10 +4597,9 @@ on_error:
 /* not thread-safe, do not use from api without first forking */
 static char *getuname(void)
 {
+       __do_free char *buf = NULL;
        struct passwd pwent;
        struct passwd *pwentp = NULL;
-       char *buf;
-       char *username;
        size_t bufsize;
        int ret;
 
@@ -4618,23 +4617,18 @@ static char *getuname(void)
                        WARN("Could not find matched password record.");
 
                ERROR("Failed to get password record - %u", geteuid());
-               free(buf);
                return NULL;
        }
 
-       username = strdup(pwent.pw_name);
-       free(buf);
-
-       return username;
+       return strdup(pwent.pw_name);
 }
 
 /* not thread-safe, do not use from api without first forking */
 static char *getgname(void)
 {
+       __do_free char *buf = NULL;
        struct group grent;
        struct group *grentp = NULL;
-       char *buf;
-       char *grname;
        size_t bufsize;
        int ret;
 
@@ -4652,14 +4646,10 @@ static char *getgname(void)
                        WARN("Could not find matched group record");
 
                ERROR("Failed to get group record - %u", getegid());
-               free(buf);
                return NULL;
        }
 
-       grname = strdup(grent.gr_name);
-       free(buf);
-
-       return grname;
+       return strdup(grent.gr_name);
 }
 
 /* not thread-safe, do not use from api without first forking */