virDomainGenerateMachineName: Use g_autofree for @username

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2020-03-18 15:45:07 +01:00
parent 06a19921b6
commit 1dd3282873

View File

@ -31080,18 +31080,17 @@ virDomainGenerateMachineName(const char *drivername,
const char *name, const char *name,
bool privileged) bool privileged)
{ {
char *username = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
if (privileged) { if (privileged) {
virBufferAsprintf(&buf, "%s-", drivername); virBufferAsprintf(&buf, "%s-", drivername);
} else { } else {
g_autofree char *username = NULL;
if (!(username = virGetUserName(geteuid()))) { if (!(username = virGetUserName(geteuid()))) {
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
return NULL; return NULL;
} }
virBufferAsprintf(&buf, "%s-%s-", username, drivername); virBufferAsprintf(&buf, "%s-%s-", username, drivername);
VIR_FREE(username);
} }
virBufferAsprintf(&buf, "%d-", id); virBufferAsprintf(&buf, "%d-", id);