From 9aa0cfdd55d5ffe9ae720f84b8f25c772260e0b5 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 18 Jul 2025 16:08:40 +0200 Subject: [PATCH] virSecuritySELinuxContextAddRange: Refactor cleanup of 'context_t' MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Use the new autoptr helper to free the temporary variables and refactor cleanup. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/security/security_selinux.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 87348f36fa..55a5593fa5 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -572,37 +572,31 @@ virSecuritySELinuxContextAddRange(const char *src, const char *dst) { const char *str = NULL; - char *ret = NULL; - context_t srccon = NULL; - context_t dstcon = NULL; + g_autoptr(context_s_t) srccon = NULL; + g_autoptr(context_s_t) dstcon = NULL; if (!src || !dst) - return ret; + return NULL; if (!(srccon = context_new(src)) || !(dstcon = context_new(dst))) { virReportSystemError(errno, "%s", _("unable to allocate security context")); - goto cleanup; + return NULL; } if (context_range_set(dstcon, context_range_get(srccon)) == -1) { virReportSystemError(errno, _("unable to set security context range '%1$s'"), dst); - goto cleanup; + return NULL; } if (!(str = context_str(dstcon))) { virReportSystemError(errno, "%s", _("Unable to format SELinux context")); - goto cleanup; + return NULL; } - ret = g_strdup(str); - - cleanup: - if (srccon) context_free(srccon); - if (dstcon) context_free(dstcon); - return ret; + return g_strdup(str); } -- 2.47.3