[virt-tools-list] [vhostmd PATCH 17/18] vhostmd: Fix memory leak in vhostmd_run

Jim Fehlig jfehlig at suse.com
Wed Jan 15 22:07:48 UTC 2020


Example from coverity scan

vhostmd-1.1/vhostmd/vhostmd.c:940: alloc_arg: "vu_buffer_create" allocates memory that is stored into "buf".
vhostmd-1.1/vhostmd/vhostmd.c:959: leaked_storage: Variable "buf" going out of scope leaks the storage it points to.
  957|            vu_log(VHOSTMD_ERR, "Failed to start virtio thread '%s'\n",
  958|                   strerror(rc));
  959|->          return -1;
  960|         }
  961|      }

Signed-off-by: Jim Fehlig <jfehlig at suse.com>
---
 vhostmd/vhostmd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c
index 1395bc5..6f3709b 100644
--- a/vhostmd/vhostmd.c
+++ b/vhostmd/vhostmd.c
@@ -967,14 +967,17 @@ static int vhostmd_run(int diskfd)
       if (virtio_expiration_time < (update_period * 3))
          virtio_expiration_time = update_period * 3;
 
-      if (virtio_init(virtio_max_channels, virtio_expiration_time))
+      if (virtio_init(virtio_max_channels, virtio_expiration_time)) {
+         vu_buffer_delete(buf);
          return -1;
+      }
 
       rc = pthread_create(&virtio_tid, NULL, virtio_run, NULL);
 
       if (rc != 0) {
          vu_log(VHOSTMD_ERR, "Failed to start virtio thread '%s'\n",
                 strerror(rc));
+         vu_buffer_delete(buf);
          return -1;
       }
    }
-- 
2.16.4





More information about the virt-tools-list mailing list