The current implementation has the following bugs:
- the vm variable is accessed after calling virDomainObjEndAPI on it
- if VIR_STRDUP fails and we jump to the cleanup section, we're calling
VIR_FREE on pointers for which we haven't allocated memory
- the error type VIR_DOMAIN_DISK_ERROR_NONE is used which contradicts
the documentation of the API that says that disks with no errors are not
reported
This patch fixes all of them and additionally reports errors only for
every second disk (instead of reporting errors for all disks) which was
the initial intention.
Signed-off-by: Ilias Stamatis <stamatis.iliass(a)gmail.com>
---
src/test/test_driver.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 2a0ffbc6c5..a7e40112d1 100755
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3246,6 +3246,7 @@ static int testDomainGetDiskErrors(virDomainPtr dom,
unsigned int flags)
{
virDomainObjPtr vm = NULL;
+ int n = 0;
int ret = -1;
size_t i;
@@ -3258,12 +3259,13 @@ static int testDomainGetDiskErrors(virDomainPtr dom,
goto cleanup;
if (errors) {
- for (i = 0; i < MIN(vm->def->ndisks, maxerrors); i++) {
- if (VIR_STRDUP(errors[i].disk, vm->def->disks[i]->dst) < 0)
+ for (i = 1; i < vm->def->ndisks && n < maxerrors; i += 2) {
+ if (VIR_STRDUP(errors[n].disk, vm->def->disks[i]->dst) < 0)
goto cleanup;
- errors[i].error = i % VIR_DOMAIN_DISK_ERROR_LAST;
+ errors[n].error = (n % (VIR_DOMAIN_DISK_ERROR_LAST - 1)) + 1;
+ n++;
}
- ret = i;
+ ret = n;
} else {
ret = vm->def->ndisks;
}
@@ -3271,7 +3273,7 @@ static int testDomainGetDiskErrors(virDomainPtr dom,
cleanup:
virDomainObjEndAPI(&vm);
if (ret < 0) {
- for (i = 0; i < MIN(vm->def->ndisks, maxerrors); i++)
+ for (i = 0; i < n; i++)
VIR_FREE(errors[i].disk);
}
return ret;
--
2.22.0