On 01/09/2013 07:54 AM, John Ferlan wrote:
Because result was used to determine whether or not to free
'priv'
resources Coverity tagged the code as having a resource leak. This
change addresses that concern.
---
src/esx/esx_driver.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 1366c81..9befa38 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -998,6 +998,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth,
virReportOOMError();
goto cleanup;
}
+ conn->privateData = priv;
if (esxUtil_ParseUri(&priv->parsedUri, conn->uri) < 0) {
goto cleanup;
I
@@ -1008,8 +1009,6 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr
auth,
priv->supportsLongMode = esxVI_Boolean_Undefined;
priv->usedCpuTimeCounterId = -1;
- conn->privateData = priv;
-
/*
* Set the port dependent on the transport protocol if no port is
* specified. This allows us to rely on the port parameter being
@@ -1104,9 +1103,10 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth,
result = VIR_DRV_OPEN_SUCCESS;
cleanup:
- if (result == VIR_DRV_OPEN_ERROR) {
+ if (result == VIR_DRV_OPEN_ERROR)
+ conn->privateData = NULL;
+ if (priv && !conn->privateData)
esxFreePrivate(&priv);
- }
This feels a bit complex; I had to go read esxFreePrivate() to make sure
it would behave if called on a partial object. Would it be any easier
to delay the assignment to conn->privateData, and use transfer of
ownership semantics, so that the cleanup is unconditional?
conn->privateData = priv;
priv = NULL;
result = VIR_DRV_OPEN_SUCCESS;
cleanup:
esxFreePrivate(&priv);
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org