From 265d0bed0b1b1f641d016cdfb035362970ac4070 Mon Sep 17 00:00:00 2001 From: Martin Kletzander Date: Mon, 21 Aug 2017 09:02:09 +0200 Subject: [PATCH] conf: Clean up and report error in virDomainGenerateMachineName Signed-off-by: Martin Kletzander --- src/conf/domain_conf.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8371fda538..d97aab4834 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27481,25 +27481,23 @@ virDomainGenerateMachineName(const char *drivername, const char *name, bool privileged) { - char *machinename = NULL; char *username = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; if (privileged) { virBufferAsprintf(&buf, "%s-", drivername); } else { - if (!(username = virGetUserName(geteuid()))) - goto cleanup; - + if (!(username = virGetUserName(geteuid()))) { + virBufferFreeAndReset(&buf); + return NULL; + } virBufferAsprintf(&buf, "%s-%s-", username, drivername); + VIR_FREE(username); } virBufferAsprintf(&buf, "%d-", id); virDomainMachineNameAppendValid(&buf, name); - machinename = virBufferContentAndReset(&buf); - cleanup: - VIR_FREE(username); - - return machinename; + virBufferCheckError(&buf); + return virBufferContentAndReset(&buf); }