From: Peter Krempa <pkre...@redhat.com>

Automatically free temporary variables in order to remove 'cleanup'
section.

Signed-off-by: Peter Krempa <pkre...@redhat.com>
---
 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.50.0

Reply via email to