This series of patches cleans up the Coverity issues reported by John.
Stefan
v1->v2: fixed patch 3
Stefan Berger (4):
tpm: Fix memory leak and use existing variable instead
tests: Call virCommandFree() in cleanup section
utils: Remove ATTRIBUTE_NONNULL(1) from virCommandSetSendBuffer
conf: Remove ATTRIBUTE_NONNULL(2) from virDomainCheckDeviceChanges()
src/conf/domain_conf.h | 3 +--
src/qemu/qemu_tpm.c | 4 ++--
src/util/vircommand.c | 3 ++-
src/util/vircommand.h | 2 +-
tests/commandtest.c | 3 +--
5 files changed, 7 insertions(+), 8 deletions(-)
--
2.20.1
Show replies by date
Use the existing variables rather then calling virTPMSwtpmXYZ().
Signed-off-by: Stefan Berger <stefanb(a)linux.ibm.com>
Reviewed-by: John Ferlan <jferlan(a)redhat.com>
---
src/qemu/qemu_tpm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
index 7efd635831..a8a4d734c0 100644
--- a/src/qemu/qemu_tpm.c
+++ b/src/qemu/qemu_tpm.c
@@ -508,7 +508,7 @@ qemuTPMEmulatorRunSetup(const char *storagepath,
VIR_TPM_SWTPM_SETUP_FEATURE_CMDARG_PWDFILE_FD)) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
_("%s does not support passing a passphrase using a file "
- "descriptor"), virTPMGetSwtpmSetup());
+ "descriptor"), swtpm_setup);
goto cleanup;
}
if ((pwdfile_fd = qemuTPMSetupEncryption(secretuuid, cmd)) < 0)
@@ -648,7 +648,7 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDefPtr tpm,
if (!virTPMSwtpmCapsGet(VIR_TPM_SWTPM_FEATURE_CMDARG_PWD_FD)) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
_("%s does not support passing passphrase via file
descriptor"),
- virTPMGetSwtpm());
+ swtpm);
goto error;
}
--
2.20.1
Fix a potential memory leak by calling virCommandFree() in the cleanup
section.
Signed-off-by: Stefan Berger <stefanb(a)linux.ibm.com>
Reviewed-by: John Ferlan <jferlan(a)redhat.com>
---
tests/commandtest.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tests/commandtest.c b/tests/commandtest.c
index 991c0572b0..dfd15a2079 100644
--- a/tests/commandtest.c
+++ b/tests/commandtest.c
@@ -1219,8 +1219,6 @@ static int test27(const void *unused ATTRIBUTE_UNUSED)
goto cleanup;
}
- virCommandFree(cmd);
-
if (!outactual || !erractual)
goto cleanup;
@@ -1236,6 +1234,7 @@ static int test27(const void *unused ATTRIBUTE_UNUSED)
ret = 0;
cleanup:
+ virCommandFree(cmd);
VIR_FORCE_CLOSE(pipe1[0]);
VIR_FORCE_CLOSE(pipe2[0]);
VIR_FORCE_CLOSE(pipe1[1]);
--
2.20.1
Remove the ATTRIBUTE_NONNULL(1) from virCommandSetSendBuffer()
prototype since we are checking for '!cmd' and move the initialization
if 'i' after the test for '!cmd'.
Signed-off-by: Stefan Berger <stefanb(a)linux.ibm.com>
Reviewed-by: John Ferlan <jferlan(a)redhat.com>
---
src/util/vircommand.c | 3 ++-
src/util/vircommand.h | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 774038e536..2df71014f8 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -1775,7 +1775,7 @@ virCommandSetSendBuffer(virCommandPtr cmd,
int fd,
unsigned char *buffer, size_t buflen)
{
- size_t i = virCommandGetNumSendBuffers(cmd);
+ size_t i;
if (!cmd || cmd->has_error)
return -1;
@@ -1787,6 +1787,7 @@ virCommandSetSendBuffer(virCommandPtr cmd,
return -1;
}
+ i = virCommandGetNumSendBuffers(cmd);
if (VIR_REALLOC_N(cmd->sendBuffers, i + 1) < 0) {
cmd->has_error = ENOMEM;
return -1;
diff --git a/src/util/vircommand.h b/src/util/vircommand.h
index c2abc7b2c3..74574e3fb1 100644
--- a/src/util/vircommand.h
+++ b/src/util/vircommand.h
@@ -149,7 +149,7 @@ void virCommandSetWorkingDirectory(virCommandPtr cmd,
int virCommandSetSendBuffer(virCommandPtr cmd,
int fd,
unsigned char *buffer, size_t buflen)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
+ ATTRIBUTE_NONNULL(3);
void virCommandSetInputBuffer(virCommandPtr cmd,
const char *inbuf) ATTRIBUTE_NONNULL(2);
--
2.20.1
Since we are checking the 2nd parameter in the function for NULL,
we need to remove ATTRIBUTE_NONNULL(2) from the prototype.
Signed-off-by: Stefan Berger <stefanb(a)linux.ibm.com>
Reviewed-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/domain_conf.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 285fa6c496..dc480bc7c5 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3638,5 +3638,4 @@ bool
virDomainGraphicsNeedsAutoRenderNode(const virDomainGraphicsDef *graphics);
int
-virDomainCheckDeviceChanges(virDomainDefPtr def, virDomainDefPtr newDef)
- ATTRIBUTE_NONNULL(2);
+virDomainCheckDeviceChanges(virDomainDefPtr def, virDomainDefPtr newDef);
--
2.20.1