Blob Blame History Raw
From 8a150535474e22c35508b075212b91478ba06de0 Mon Sep 17 00:00:00 2001
Message-Id: <8a150535474e22c35508b075212b91478ba06de0.1377873641.git.jdenemar@redhat.com>
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
Date: Wed, 28 Aug 2013 10:24:12 +0200
Subject: [PATCH] virsh: free the list from ListAll APIs even for 0 items

https://bugzilla.redhat.com/show_bug.cgi?id=1001957

virsh secret-list leak when no secrets are defined:

==27== 8 bytes in 1 blocks are definitely lost in loss record 6 of 726
==27==    by 0x4E941DD: virAllocN (viralloc.c:183)
==27==    by 0x5037F1A: remoteConnectListAllSecrets (remote_driver.c:3076)
==27==    by 0x5004EC6: virConnectListAllSecrets (libvirt.c:16298)
==27==    by 0x15F813: vshSecretListCollect (virsh-secret.c:397)
==27==    by 0x15F0E1: cmdSecretList (virsh-secret.c:532)

And so do some other *-list commands.

https://bugzilla.redhat.com/show_bug.cgi?id=1001536
(cherry picked from commit f733eac058b373822708d3ec889dd80e281fa7e1)
---
 tools/virsh-interface.c | 2 +-
 tools/virsh-network.c   | 2 +-
 tools/virsh-nodedev.c   | 2 +-
 tools/virsh-nwfilter.c  | 2 +-
 tools/virsh-secret.c    | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c
index 0f78551..3720c8c 100644
--- a/tools/virsh-interface.c
+++ b/tools/virsh-interface.c
@@ -174,7 +174,7 @@ vshInterfaceListFree(vshInterfaceListPtr list)
 {
     size_t i;
 
-    if (list && list->nifaces) {
+    if (list && list->ifaces) {
         for (i = 0; i < list->nifaces; i++) {
             if (list->ifaces[i])
                 virInterfaceFree(list->ifaces[i]);
diff --git a/tools/virsh-network.c b/tools/virsh-network.c
index 06bf483..8ddd5ca 100644
--- a/tools/virsh-network.c
+++ b/tools/virsh-network.c
@@ -423,7 +423,7 @@ vshNetworkListFree(vshNetworkListPtr list)
 {
     size_t i;
 
-    if (list && list->nnets) {
+    if (list && list->nets) {
         for (i = 0; i < list->nnets; i++) {
             if (list->nets[i])
                 virNetworkFree(list->nets[i]);
diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index 92ef40c..3a2d12b 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -207,7 +207,7 @@ vshNodeDeviceListFree(vshNodeDeviceListPtr list)
 {
     size_t i;
 
-    if (list && list->ndevices) {
+    if (list && list->devices) {
         for (i = 0; i < list->ndevices; i++) {
             if (list->devices[i])
                 virNodeDeviceFree(list->devices[i]);
diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c
index fbf211a..e5fcb8f 100644
--- a/tools/virsh-nwfilter.c
+++ b/tools/virsh-nwfilter.c
@@ -242,7 +242,7 @@ vshNWFilterListFree(vshNWFilterListPtr list)
 {
     size_t i;
 
-    if (list && list->nfilters) {
+    if (list && list->filters) {
         for (i = 0; i < list->nfilters; i++) {
             if (list->filters[i])
                 virNWFilterFree(list->filters[i]);
diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c
index 9d34c1a..c4763e3 100644
--- a/tools/virsh-secret.c
+++ b/tools/virsh-secret.c
@@ -369,7 +369,7 @@ vshSecretListFree(vshSecretListPtr list)
 {
     size_t i;
 
-    if (list && list->nsecrets) {
+    if (list && list->secrets) {
         for (i = 0; i < list->nsecrets; i++) {
             if (list->secrets[i])
                 virSecretFree(list->secrets[i]);
-- 
1.8.3.2