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

Martin Kletzander mkletzan at redhat.com
Tue Sep 2 13:27:14 UTC 2014


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 at redhat.com
>https://www.redhat.com/mailman/listinfo/libvir-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140902/8084ed64/attachment-0001.sig>


More information about the libvir-list mailing list