[libvirt] [PATCH] remote: Fix memory leak on error path when deserializing bulk stats

The 'elem' variable along with the domain object would be leaked when taking the error path. Found by coverity. --- src/remote/remote_driver.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index fda27f7..8bc4baa 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -7730,7 +7730,7 @@ remoteConnectGetAllDomainStats(virConnectPtr conn, size_t i; remote_connect_get_all_domain_stats_args args; remote_connect_get_all_domain_stats_ret ret; - + virDomainStatsRecordPtr elem = NULL; virDomainStatsRecordPtr *tmpret = NULL; if (ndoms) { @@ -7769,7 +7769,6 @@ remoteConnectGetAllDomainStats(virConnectPtr conn, goto cleanup; for (i = 0; i < ret.retStats.retStats_len; i++) { - virDomainStatsRecordPtr elem; remote_domain_stats_record *rec = ret.retStats.retStats_val + i; if (VIR_ALLOC(elem) < 0) @@ -7786,6 +7785,7 @@ remoteConnectGetAllDomainStats(virConnectPtr conn, goto cleanup; tmpret[i] = elem; + elem = NULL; } *retStats = tmpret; @@ -7793,6 +7793,10 @@ remoteConnectGetAllDomainStats(virConnectPtr conn, rv = ret.retStats.retStats_len; cleanup: + if (elem) { + virObjectUnref(elem->dom); + VIR_FREE(elem); + } virDomainStatsRecordListFree(tmpret); xdr_free((xdrproc_t)xdr_remote_connect_get_all_domain_stats_ret, (char *) &ret); -- 2.0.2

On Tue, Sep 02, 2014 at 03:18:39PM +0200, Peter Krempa wrote:
The 'elem' variable along with the domain object would be leaked when taking the error path.
Found by coverity. --- src/remote/remote_driver.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
ACK, Martin
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index fda27f7..8bc4baa 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -7730,7 +7730,7 @@ remoteConnectGetAllDomainStats(virConnectPtr conn, size_t i; remote_connect_get_all_domain_stats_args args; remote_connect_get_all_domain_stats_ret ret; - + virDomainStatsRecordPtr elem = NULL; virDomainStatsRecordPtr *tmpret = NULL;
if (ndoms) { @@ -7769,7 +7769,6 @@ remoteConnectGetAllDomainStats(virConnectPtr conn, goto cleanup;
for (i = 0; i < ret.retStats.retStats_len; i++) { - virDomainStatsRecordPtr elem; remote_domain_stats_record *rec = ret.retStats.retStats_val + i;
if (VIR_ALLOC(elem) < 0) @@ -7786,6 +7785,7 @@ remoteConnectGetAllDomainStats(virConnectPtr conn, goto cleanup;
tmpret[i] = elem; + elem = NULL; }
*retStats = tmpret; @@ -7793,6 +7793,10 @@ remoteConnectGetAllDomainStats(virConnectPtr conn, rv = ret.retStats.retStats_len;
cleanup: + if (elem) { + virObjectUnref(elem->dom); + VIR_FREE(elem); + } virDomainStatsRecordListFree(tmpret); xdr_free((xdrproc_t)xdr_remote_connect_get_all_domain_stats_ret, (char *) &ret); -- 2.0.2
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 09/02/14 15:27, Martin Kletzander wrote:
On Tue, Sep 02, 2014 at 03:18:39PM +0200, Peter Krempa wrote:
The 'elem' variable along with the domain object would be leaked when taking the error path.
Found by coverity. --- src/remote/remote_driver.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
ACK,
Martin
Pushed; Thanks. Peter
participants (2)
-
Martin Kletzander
-
Peter Krempa