From 1be713649530e92e307c73cda0facfe5705ce443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 19 Dec 2019 10:40:37 +0100 Subject: [PATCH] admin: Use g_autofree in getSocketPath() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabiano FidĂȘncio Reviewed-by: Michal Privoznik --- src/admin/libvirt-admin.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/admin/libvirt-admin.c b/src/admin/libvirt-admin.c index f156736d9f..8a43dbf1de 100644 --- a/src/admin/libvirt-admin.c +++ b/src/admin/libvirt-admin.c @@ -99,12 +99,12 @@ virAdmInitialize(void) static char * getSocketPath(virURIPtr uri) { - char *rundir = virGetUserRuntimeDirectory(); - char *sock_path = NULL; + g_autofree char *rundir = virGetUserRuntimeDirectory(); + g_autofree char *sock_path = NULL; size_t i = 0; if (!uri) - goto cleanup; + return NULL; for (i = 0; i < uri->paramsCount; i++) { @@ -116,7 +116,7 @@ getSocketPath(virURIPtr uri) } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown URI parameter '%s'"), param->name); - goto error; + return NULL; } } @@ -127,7 +127,7 @@ getSocketPath(virURIPtr uri) if (!uri->scheme) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("No URI scheme specified")); - goto error; + return NULL; } if (STREQ(uri->scheme, "libvirtd")) { legacy = true; @@ -135,7 +135,7 @@ getSocketPath(virURIPtr uri) virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported URI scheme '%s'"), uri->scheme); - goto error; + return NULL; } if (legacy) { @@ -148,24 +148,18 @@ getSocketPath(virURIPtr uri) sock_path = g_strdup_printf(RUNSTATEDIR "/libvirt/%s", sockbase); } else if (STREQ_NULLABLE(uri->path, "/session")) { if (!rundir) - goto error; + return NULL; sock_path = g_strdup_printf("%s/%s", rundir, sockbase); } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid URI path '%s', try '/system'"), NULLSTR_EMPTY(uri->path)); - goto error; + return NULL; } } - cleanup: - VIR_FREE(rundir); - return sock_path; - - error: - VIR_FREE(sock_path); - goto cleanup; + return g_steal_pointer(&sock_path); } static int