[dpdk-dev] net/virtio: fix memory leak

Message ID 1509076449-20542-1-git-send-email-liupengzhen3@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: Yuanhan Liu
Headers

Checks

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

Commit Message

Pengzhen Liu Oct. 27, 2017, 3:54 a.m. UTC
  In function eth_virtio_dev_init(), dynamic memory stored
in "eth_dev->data->mac_addrs" variable and it is not freed
when function return,
this is a possible memory leak.

Fixes: 8ced1542f7a3 ("net/virtio: eth_dev->data->mac_addrs is not freed")
Cc: stable@dpdk.org
Signed-off-by: Pengzhen Liu <liupengzhen3@huawei.com>
---
 drivers/net/virtio/virtio_ethdev.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
  

Comments

Yuanhan Liu Nov. 1, 2017, 3:33 p.m. UTC | #1
On Fri, Oct 27, 2017 at 11:54:09AM +0800, Pengzhen Liu wrote:
> In function eth_virtio_dev_init(), dynamic memory stored
> in "eth_dev->data->mac_addrs" variable and it is not freed
> when function return,
> this is a possible memory leak.
> 
> Fixes: 8ced1542f7a3 ("net/virtio: eth_dev->data->mac_addrs is not freed")
> Cc: stable@dpdk.org
> Signed-off-by: Pengzhen Liu <liupengzhen3@huawei.com>

Acked-by: Yuanhan Liu <yliu@fridaylinux.org>

	--yliu
  
Yuanhan Liu Nov. 1, 2017, 3:49 p.m. UTC | #2
On Wed, Nov 01, 2017 at 11:33:51PM +0800, Yuanhan Liu wrote:
> On Fri, Oct 27, 2017 at 11:54:09AM +0800, Pengzhen Liu wrote:
> > In function eth_virtio_dev_init(), dynamic memory stored
> > in "eth_dev->data->mac_addrs" variable and it is not freed
> > when function return,
> > this is a possible memory leak.
> > 
> > Fixes: 8ced1542f7a3 ("net/virtio: eth_dev->data->mac_addrs is not freed")
> > Cc: stable@dpdk.org
> > Signed-off-by: Pengzhen Liu <liupengzhen3@huawei.com>
> 
> Acked-by: Yuanhan Liu <yliu@fridaylinux.org>

BTW, I have just seen you have send multiple versions out regarding this
patch. Next time please tag your patches with version, something like:

    $ git format-patch -v 2 ...
	
	--yliu
  
Thomas Monjalon Nov. 12, 2017, 6:53 p.m. UTC | #3
01/11/2017 16:33, Yuanhan Liu:
> On Fri, Oct 27, 2017 at 11:54:09AM +0800, Pengzhen Liu wrote:
> > In function eth_virtio_dev_init(), dynamic memory stored
> > in "eth_dev->data->mac_addrs" variable and it is not freed
> > when function return,
> > this is a possible memory leak.
> > 
> > Fixes: 8ced1542f7a3 ("net/virtio: eth_dev->data->mac_addrs is not freed")
> > Cc: stable@dpdk.org
> > Signed-off-by: Pengzhen Liu <liupengzhen3@huawei.com>
> 
> Acked-by: Yuanhan Liu <yliu@fridaylinux.org>

Applied, thanks
  

Patch

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index a8ae788..59a76ad 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1588,13 +1588,13 @@  static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
 	if (!hw->virtio_user_dev) {
 		ret = vtpci_init(RTE_ETH_DEV_TO_PCI(eth_dev), hw);
 		if (ret)
-			return ret;
+			goto out;
 	}
 
 	/* reset device and negotiate default features */
 	ret = virtio_init_device(eth_dev, VIRTIO_PMD_DEFAULT_GUEST_FEATURES);
 	if (ret < 0)
-		return ret;
+		goto out;
 
 	/* Setup interrupt callback  */
 	if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
@@ -1602,6 +1602,10 @@  static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
 			virtio_interrupt_handler, eth_dev);
 
 	return 0;
+
+out:
+	rte_free(eth_dev->data->mac_addrs);
+	return ret;
 }
 
 static int