]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Fix resource leak in virCapabilitiesInitCaches
authorJohn Ferlan <jferlan@redhat.com>
Fri, 12 May 2017 10:46:20 +0000 (06:46 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 12 May 2017 10:46:20 +0000 (06:46 -0400)
The @type from virFileReadValueString needs to be VIR_FREE each time
through the loop since it's not saved and since cleanup can be reached
prior to decoding it for @kernel_type amd bank->type, the cleanup code
needs to also have a VIR_FREE

Found by Coverity

src/conf/capabilities.c

index c36ca4088976e0e3ca1e8c7aa6725daa5e602d5a..d699b081730f804de24f3ec5703867fe55549bf0 100644 (file)
@@ -1611,10 +1611,10 @@ virCapabilitiesInitCaches(virCapsPtr caps)
             if (kernel_type < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("Unknown cache type '%s'"), type);
-                VIR_FREE(type);
                 goto cleanup;
             }
             bank->type = kernel_type;
+            VIR_FREE(type);
 
             for (i = 0; i < caps->host.ncaches; i++) {
                 if (virCapsHostCacheBankEquals(bank, caps->host.caches[i]))
@@ -1637,6 +1637,7 @@ virCapabilitiesInitCaches(virCapsPtr caps)
 
     ret = 0;
  cleanup:
+    VIR_FREE(type);
     VIR_FREE(path);
     virDirClose(&dirp);
     virCapsHostCacheBankFree(bank);