]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
test_driver: Don't access @vm after it was set to NULL
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 14 May 2019 15:05:45 +0000 (17:05 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 3 Jul 2019 07:06:41 +0000 (09:06 +0200)
If something goes wrong in testDomainGetDiskErrors() then we try
to free any strings that were previously allocated in return
array. Problem is, in my review of original patch (89320788ac4)
I've mistakenly did some changes which result in possible NULL
dereference (@vm is set to NULL as the first thing under cleanup
label).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
src/test/test_driver.c

index 4b1f2724a03e81d7c5e86518abf699517b3d8eb4..e3545e70857257d1b238f924351af4ffb5f109d0 100644 (file)
@@ -3268,7 +3268,7 @@ static int testDomainGetDiskErrors(virDomainPtr dom,
     virCheckFlags(0, -1);
 
     if (!(vm = testDomObjFromDomain(dom)))
-        goto cleanup;
+        return -1;
 
     if (virDomainObjCheckActive(vm) < 0)
         goto cleanup;
@@ -3285,11 +3285,11 @@ static int testDomainGetDiskErrors(virDomainPtr dom,
     }
 
  cleanup:
-    virDomainObjEndAPI(&vm);
     if (ret < 0) {
         for (i = 0; i < MIN(vm->def->ndisks, maxerrors); i++)
             VIR_FREE(errors[i].disk);
     }
+    virDomainObjEndAPI(&vm);
     return ret;
 }