From aa732b42721eb648f21c7ec6884012101a2ecded Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 18 Jul 2025 16:41:10 +0200 Subject: [PATCH] virSecuritySELinuxGenImageLabel: Refactor cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Automatically free temporary variables in order to remove 'cleanup' section. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/security/security_selinux.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index b16ab14dfe..9d14e33340 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -3495,34 +3495,29 @@ virSecuritySELinuxGenImageLabel(virSecurityManager *mgr, virSecurityLabelDef *secdef; virSecuritySELinuxData *data = virSecurityManagerGetPrivateData(mgr); const char *range; - context_t ctx = NULL; - char *label = NULL; - char *mcs = NULL; + g_autoptr(context_s_t) ctx = NULL; secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); if (secdef == NULL) - goto cleanup; + return NULL; if (secdef->label) { ctx = context_new(secdef->label); if (!ctx) { virReportSystemError(errno, _("unable to create selinux context for: %1$s"), secdef->label); - goto cleanup; + return NULL; } range = context_range_get(ctx); if (range) { - mcs = g_strdup(range); - if (!(label = virSecuritySELinuxGenNewContext(data->file_context, - mcs, true))) - goto cleanup; + g_autofree char *mcs = g_strdup(range); + + return virSecuritySELinuxGenNewContext(data->file_context, + mcs, true); } } - cleanup: - context_free(ctx); - VIR_FREE(mcs); - return label; + return NULL; } static char * -- 2.47.2