From: Peter Krempa Date: Fri, 18 Jul 2025 14:17:59 +0000 (+0200) Subject: virSecuritySELinuxReserveLabel: Refactor cleanup X-Git-Tag: v11.6.0-rc1~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6bb5993897328c0572a2cc1a54943714b084f500;p=thirdparty%2Flibvirt.git virSecuritySELinuxReserveLabel: 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 67d9da461a..3004320380 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1025,8 +1025,8 @@ virSecuritySELinuxReserveLabel(virSecurityManager *mgr, virDomainDef *def, pid_t pid) { - char *pctx; - context_t ctx = NULL; + g_autofree char *pctx = NULL; + g_autoptr(context_s_t) ctx = NULL; const char *mcs; int rv; virSecurityLabelDef *seclabel; @@ -1045,31 +1045,23 @@ virSecuritySELinuxReserveLabel(virSecurityManager *mgr, ctx = context_new(pctx); if (!ctx) - goto error; + return -1; mcs = context_range_get(ctx); if (!mcs) - goto error; + return -1; if ((rv = virSecuritySELinuxMCSAdd(mgr, mcs)) < 0) - goto error; + return -1; if (rv == 1) { virReportError(VIR_ERR_INTERNAL_ERROR, _("MCS level for existing domain label %1$s already reserved"), (char*)pctx); - goto error; + return -1; } - freecon(pctx); - context_free(ctx); - return 0; - - error: - freecon(pctx); - context_free(ctx); - return -1; }