From: Peter Krempa Date: Fri, 18 Jul 2025 14:41:10 +0000 (+0200) Subject: virSecuritySELinuxGenImageLabel: Refactor cleanup X-Git-Tag: v11.6.0-rc1~48 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aa732b42721eb648f21c7ec6884012101a2ecded;p=thirdparty%2Flibvirt.git virSecuritySELinuxGenImageLabel: Refactor cleanup Automatically free temporary variables in order to remove 'cleanup' section. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- 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 *