]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: reduce variable scope in testSELinuxCheckLabels
authorJán Tomko <jtomko@redhat.com>
Fri, 3 Sep 2021 19:16:41 +0000 (21:16 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 8 Sep 2021 13:31:01 +0000 (15:31 +0200)
And use g_auto.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
tests/securityselinuxlabeltest.c

index f7dd3c866a6ba6c7bb233799e7dd6bfad0f5fe80..3d886fd82701be573bbd7fc4174569eb5034390e 100644 (file)
@@ -246,10 +246,9 @@ static int
 testSELinuxCheckLabels(testSELinuxFile *files, size_t nfiles)
 {
     size_t i;
-    char *ctx;
 
     for (i = 0; i < nfiles; i++) {
-        ctx = NULL;
+        g_autofree char *ctx = NULL;
         if (getfilecon(files[i].file, &ctx) < 0) {
             if (errno == ENODATA) {
                 /* nothing to do */
@@ -266,10 +265,8 @@ testSELinuxCheckLabels(testSELinuxFile *files, size_t nfiles)
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            "File %s context '%s' did not match expected '%s'",
                            files[i].file, ctx, files[i].context);
-            VIR_FREE(ctx);
             return -1;
         }
-        VIR_FREE(ctx);
     }
     return 0;
 }