[libvirt] [PATCH 0/3] A couple of Coverity found issues

There's more, but many are false positives and there's also a couple more that I have to think more deeply about... John Ferlan (3): tests: Pass BlockIOThrottle arguments by reference not value qemu: Initialize 'data' argument qemu: Fix resource leak in qemuDomainAddChardevTLSObjects error path src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_migration.c | 11 ++++++++--- tests/qemumonitorjsontest.c | 38 +++++++++++++++++++------------------- 3 files changed, 28 insertions(+), 23 deletions(-) -- 2.9.3

Pass the data by reference rather than everything on the stack. Signed-off-by: John Ferlan <jferlan@redhat.com> --- tests/qemumonitorjsontest.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 5d53609..ac87c9c 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2035,27 +2035,27 @@ testQemuMonitorJSONqemuMonitorJSONGetChardevInfo(const void *data) static int -testValidateGetBlockIoThrottle(virDomainBlockIoTuneInfo info, - virDomainBlockIoTuneInfo expectedInfo) +testValidateGetBlockIoThrottle(const virDomainBlockIoTuneInfo *info, + const virDomainBlockIoTuneInfo *expectedInfo) { #define VALIDATE_IOTUNE(field) \ - if (info.field != expectedInfo.field) { \ + if (info->field != expectedInfo->field) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ - "info.%s=%llu != expected=%llu", \ - #field, info.field, expectedInfo.field); \ + "info->%s=%llu != expected=%llu", \ + #field, info->field, expectedInfo->field); \ return -1; \ } \ - if (info.field##_max != expectedInfo.field##_max) { \ + if (info->field##_max != expectedInfo->field##_max) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ - "info.%s_max=%llu != expected=%llu", \ - #field, info.field##_max, expectedInfo.field##_max); \ + "info->%s_max=%llu != expected=%llu", \ + #field, info->field##_max, expectedInfo->field##_max); \ return -1; \ } \ - if (info.field##_max_length != expectedInfo.field##_max_length) { \ + if (info->field##_max_length != expectedInfo->field##_max_length) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ - "info.%s_max_length=%llu != expected=%llu", \ - #field, info.field##_max_length, \ - expectedInfo.field##_max_length); \ + "info->%s_max_length=%llu != expected=%llu", \ + #field, info->field##_max_length, \ + expectedInfo->field##_max_length); \ return -1; \ } VALIDATE_IOTUNE(total_bytes_sec); @@ -2064,16 +2064,16 @@ testValidateGetBlockIoThrottle(virDomainBlockIoTuneInfo info, VALIDATE_IOTUNE(total_iops_sec); VALIDATE_IOTUNE(read_iops_sec); VALIDATE_IOTUNE(write_iops_sec); - if (info.size_iops_sec != expectedInfo.size_iops_sec) { + if (info->size_iops_sec != expectedInfo->size_iops_sec) { virReportError(VIR_ERR_INTERNAL_ERROR, - "info.size_iops_sec=%llu != expected=%llu", - info.size_iops_sec, expectedInfo.size_iops_sec); + "info->size_iops_sec=%llu != expected=%llu", + info->size_iops_sec, expectedInfo->size_iops_sec); return -1; } - if (STRNEQ(info.group_name, expectedInfo.group_name)) { + if (STRNEQ(info->group_name, expectedInfo->group_name)) { virReportError(VIR_ERR_INTERNAL_ERROR, - "info.group_name=%s != expected=%s", - info.group_name, expectedInfo.group_name); + "info->group_name=%s != expected=%s", + info->group_name, expectedInfo->group_name); return -1; } #undef VALIDATE_IOTUNE @@ -2121,7 +2121,7 @@ testQemuMonitorJSONqemuMonitorJSONSetBlockIoThrottle(const void *data) "drive-virtio-disk0", &info) < 0) goto cleanup; - if (testValidateGetBlockIoThrottle(info, expectedInfo) < 0) + if (testValidateGetBlockIoThrottle(&info, &expectedInfo) < 0) goto cleanup; if (qemuMonitorJSONSetBlockIoThrottle(qemuMonitorTestGetMonitor(test), -- 2.9.3

Initialize stack variable to {0} Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/qemu/qemu_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e1ad243..388af4f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10265,7 +10265,7 @@ qemuDomainGetSchedulerParametersFlags(virDomainPtr dom, { virQEMUDriverPtr driver = dom->conn->privateData; virDomainObjPtr vm = NULL; - virDomainCputune data; + virDomainCputune data = {0}; int ret = -1; bool cpu_bw_status = true; virDomainDefPtr persistentDef; -- 2.9.3

On any failure, call virJSONValueFree for the *Props. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/qemu/qemu_migration.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 87d7dcd..852d85b 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -213,7 +213,7 @@ qemuMigrationAddTLSObjects(virQEMUDriverPtr driver, cfg->migrateTLSx509verify, QEMU_MIGRATION_TLS_ALIAS_BASE, &tlsProps, tlsAlias, &secProps, secAlias) < 0) - return -1; + goto error; /* Ensure the domain doesn't already have the TLS objects defined... * This should prevent any issues just in case some cleanup wasn't @@ -223,12 +223,17 @@ qemuMigrationAddTLSObjects(virQEMUDriverPtr driver, if (qemuDomainAddTLSObjects(driver, vm, asyncJob, *secAlias, &secProps, *tlsAlias, &tlsProps) < 0) - return -1; + goto error; if (VIR_STRDUP(migParams->migrateTLSAlias, *tlsAlias) < 0) - return -1; + goto error; return 0; + + error: + virJSONValueFree(tlsProps); + virJSONValueFree(secProps); + return -1; } -- 2.9.3
participants (2)
-
John Ferlan
-
Pavel Hrdina