]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virSecuritySELinuxReserveLabel: Refactor cleanup
authorPeter Krempa <pkrempa@redhat.com>
Fri, 18 Jul 2025 14:17:59 +0000 (16:17 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 22 Jul 2025 14:52:35 +0000 (16:52 +0200)
Automatically free temporary variables in order to remove 'cleanup'
section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/security/security_selinux.c

index 67d9da461a7160d1dcedc7b633d74dfa4a508804..3004320380644ba93c2d4f630239dde8f79bb8b2 100644 (file)
@@ -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;
 }