From: Barrett Schonefeld <bschoney@xxxxxxxxxx> - src/util/virutil.c Signed-off-by: Barrett Schonefeld <bschoney@xxxxxxxxxx> --- src/util/virutil.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/util/virutil.c b/src/util/virutil.c index a0cd0f1bcd..d4b864d5cb 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -598,7 +598,7 @@ char *virGetUserRuntimeDirectory(void) static int virGetUserEnt(uid_t uid, char **name, gid_t *group, char **dir, char **shell, bool quiet) { - char *strbuf; + g_autofree char *strbuf = NULL; struct passwd pwbuf; struct passwd *pw = NULL; long val = sysconf(_SC_GETPW_R_SIZE_MAX); @@ -668,13 +668,12 @@ virGetUserEnt(uid_t uid, char **name, gid_t *group, char **dir, char **shell, bo if (shell) VIR_FREE(*shell); } - VIR_FREE(strbuf); return ret; } static char *virGetGroupEnt(gid_t gid) { - char *strbuf; + g_autofree char *strbuf = NULL; char *ret; struct group grbuf; struct group *gr = NULL; @@ -717,7 +716,6 @@ static char *virGetGroupEnt(gid_t gid) } ret = g_strdup(gr->gr_name); - VIR_FREE(strbuf); return ret; } @@ -759,7 +757,7 @@ char *virGetGroupName(gid_t gid) static int virGetUserIDByName(const char *name, uid_t *uid, bool missing_ok) { - char *strbuf = NULL; + g_autofree char *strbuf = NULL; struct passwd pwbuf; struct passwd *pw = NULL; long val = sysconf(_SC_GETPW_R_SIZE_MAX); @@ -796,8 +794,6 @@ virGetUserIDByName(const char *name, uid_t *uid, bool missing_ok) ret = 0; cleanup: - VIR_FREE(strbuf); - return ret; } @@ -840,7 +836,7 @@ virGetUserID(const char *user, uid_t *uid) static int virGetGroupIDByName(const char *name, gid_t *gid, bool missing_ok) { - char *strbuf = NULL; + g_autofree char *strbuf = NULL; struct group grbuf; struct group *gr = NULL; long val = sysconf(_SC_GETGR_R_SIZE_MAX); @@ -877,8 +873,6 @@ virGetGroupIDByName(const char *name, gid_t *gid, bool missing_ok) ret = 0; cleanup: - VIR_FREE(strbuf); - return ret; } @@ -949,7 +943,7 @@ int virGetGroupList(uid_t uid, gid_t gid, gid_t **list) { int ret = 0; - char *user = NULL; + g_autofree char *user = NULL; gid_t primary; *list = NULL; @@ -999,7 +993,6 @@ virGetGroupList(uid_t uid, gid_t gid, gid_t **list) } cleanup: - VIR_FREE(user); return ret; } @@ -1405,8 +1398,8 @@ virSetDeviceUnprivSGIO(const char *path, const char *sysfs_dir, int unpriv_sgio) { - char *sysfs_path = NULL; - char *val = NULL; + g_autofree char *sysfs_path = NULL; + g_autofree char *val = NULL; int ret = -1; int rc; @@ -1428,8 +1421,6 @@ virSetDeviceUnprivSGIO(const char *path, ret = 0; cleanup: - VIR_FREE(sysfs_path); - VIR_FREE(val); return ret; } @@ -1438,8 +1429,8 @@ virGetDeviceUnprivSGIO(const char *path, const char *sysfs_dir, int *unpriv_sgio) { - char *sysfs_path = NULL; - char *buf = NULL; + g_autofree char *sysfs_path = NULL; + g_autofree char *buf = NULL; char *tmp = NULL; int ret = -1; @@ -1466,8 +1457,6 @@ virGetDeviceUnprivSGIO(const char *path, ret = 0; cleanup: - VIR_FREE(sysfs_path); - VIR_FREE(buf); return ret; } @@ -1488,7 +1477,7 @@ virParseOwnershipIds(const char *label, uid_t *uidPtr, gid_t *gidPtr) int rc = -1; uid_t theuid; gid_t thegid; - char *tmp_label = NULL; + g_autofree char *tmp_label = NULL; char *sep = NULL; char *owner = NULL; char *group = NULL; @@ -1522,8 +1511,6 @@ virParseOwnershipIds(const char *label, uid_t *uidPtr, gid_t *gidPtr) rc = 0; cleanup: - VIR_FREE(tmp_label); - return rc; } -- 2.29.0