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

Message ID 1509007962-652-1-git-send-email-liupengzhen3@huawei.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation fail apply patch file failure

Commit Message

Pengzhen Liu Oct. 26, 2017, 8:52 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: 6b9ed026a870 ("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, 4 insertions(+), 4 deletions(-)
  

Comments

Maxime Coquelin Oct. 26, 2017, 8:30 a.m. UTC | #1
Hi Pengzhen,

On 10/26/2017 10:52 AM, 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: 6b9ed026a870 ("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, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
> index c85c14d..c450f25 100644
> --- a/drivers/net/virtio/virtio_ethdev.c
> +++ b/drivers/net/virtio/virtio_ethdev.c
> @@ -1587,13 +1587,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)
> -            goto out;
> +			goto out;
I think you missed to squash your patch with the initial one, as tis one
only fixes indentation.

Could you resend a squashed version, and tag it as v2?

Thanks,
Maxime


>   	}
>   
>   	/* reset device and negotiate default features */
>   	ret = virtio_init_device(eth_dev, VIRTIO_PMD_DEFAULT_GUEST_FEATURES);
>   	if (ret < 0)
> -        goto out;
> +		goto out;
>   
>   	/* Setup interrupt callback  */
>   	if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
> @@ -1603,8 +1603,8 @@ static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
>   	return 0;
>   
>   out:
> -    rte_free(eth_dev->data->mac_addrs);
> -    return ret;
> +	rte_free(eth_dev->data->mac_addrs);
> +	return ret;
>   }
>   
>   static int
>
  

Patch

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index c85c14d..c450f25 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1587,13 +1587,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)
-            goto out;
+			goto out;
 	}
 
 	/* reset device and negotiate default features */
 	ret = virtio_init_device(eth_dev, VIRTIO_PMD_DEFAULT_GUEST_FEATURES);
 	if (ret < 0)
-        goto out;
+		goto out;
 
 	/* Setup interrupt callback  */
 	if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
@@ -1603,8 +1603,8 @@  static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
 	return 0;
 
 out:
-    rte_free(eth_dev->data->mac_addrs);
-    return ret;
+	rte_free(eth_dev->data->mac_addrs);
+	return ret;
 }
 
 static int