]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virSecuritySELinuxContextAddRange: Refactor cleanup of 'context_t'
authorPeter Krempa <pkrempa@redhat.com>
Fri, 18 Jul 2025 14:08:40 +0000 (16:08 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 22 Jul 2025 14:52:35 +0000 (16:52 +0200)
Use the new autoptr helper to free the temporary variables and refactor
cleanup.

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

index 87348f36fa62afc96045e6f19779f881c0a83dec..55a5593fa537e9437c5cb25914e3ef6d98a107b4 100644 (file)
@@ -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);
 }