[dpdk-dev,v3,2/3] vhost: free guest_pages in vhost_backend_cleanup()

Message ID 1494513192-85863-3-git-send-email-dariuszx.stojaczyk@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Yuanhan Liu
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Stojaczyk, DariuszX May 11, 2017, 2:33 p.m. UTC
  This patch fixes a memory leak.
virtio_net::guest_pages is allocated in vhost_setup_mem_table(),
reallocated in add_one_guest_page(), but never freed.

Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
---
 lib/librte_vhost/vhost_user.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Jens Freimann May 11, 2017, 2:31 p.m. UTC | #1
On Thu, May 11, 2017 at 04:33:11PM +0200, Dariusz Stojaczyk wrote:
> This patch fixes a memory leak.
> virtio_net::guest_pages is allocated in vhost_setup_mem_table(),
> reallocated in add_one_guest_page(), but never freed.
> 
> Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
> ---
>  lib/librte_vhost/vhost_user.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 

Reviewed-by: Jens Freimann <jfreimann@redhat.com>
  

Patch

diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index 5c8058b..2cc0b66 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -114,6 +114,10 @@  vhost_backend_cleanup(struct virtio_net *dev)
 		rte_free(dev->mem);
 		dev->mem = NULL;
 	}
+
+	free(dev->guest_pages);
+	dev->guest_pages = NULL;
+
 	if (dev->log_addr) {
 		munmap((void *)(uintptr_t)dev->log_addr, dev->log_size);
 		dev->log_addr = 0;