net/vhost: fix potential memory leak

Message ID 20200303000329.823-1-oda@valinux.co.jp (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series net/vhost: fix potential memory leak |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/Intel-compilation success Compilation OK

Commit Message

Itsuro Oda March 3, 2020, 12:03 a.m. UTC
  If a vhost device is closed before eth_dev_configure is done
to the device, internal resources allocated to the device
does not freed. This patch fixes it.

Fixes: 3d01b759d267 ("net/vhost: delay driver setup")

Signed-off-by: Itsuro Oda <oda@valinux.co.jp>
---
 drivers/net/vhost/rte_eth_vhost.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
  

Comments

Xiaolong Ye March 5, 2020, 2:15 a.m. UTC | #1
On 03/03, Itsuro Oda wrote:
>If a vhost device is closed before eth_dev_configure is done
>to the device, internal resources allocated to the device
>does not freed. This patch fixes it.

s/does not freed/would not be freed

>
>Fixes: 3d01b759d267 ("net/vhost: delay driver setup")

Cc: stable@dpdk.org

>
>Signed-off-by: Itsuro Oda <oda@valinux.co.jp>
>---
> drivers/net/vhost/rte_eth_vhost.c | 16 +++++++---------
> 1 file changed, 7 insertions(+), 9 deletions(-)
>
>diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
>index 458ed58f5..1ed977e9b 100644
>--- a/drivers/net/vhost/rte_eth_vhost.c
>+++ b/drivers/net/vhost/rte_eth_vhost.c
>@@ -1065,16 +1065,14 @@ eth_dev_close(struct rte_eth_dev *dev)
> 
> 	eth_dev_stop(dev);
> 
>-	rte_vhost_driver_unregister(internal->iface_name);
>-
> 	list = find_internal_resource(internal->iface_name);
>-	if (!list)
>-		return;
>-
>-	pthread_mutex_lock(&internal_list_lock);
>-	TAILQ_REMOVE(&internal_list, list, next);
>-	pthread_mutex_unlock(&internal_list_lock);
>-	rte_free(list);
>+	if (list) {
>+		rte_vhost_driver_unregister(internal->iface_name);
>+		pthread_mutex_lock(&internal_list_lock);
>+		TAILQ_REMOVE(&internal_list, list, next);
>+		pthread_mutex_unlock(&internal_list_lock);
>+		rte_free(list);
>+	}
> 
> 	if (dev->data->rx_queues)
> 		for (i = 0; i < dev->data->nb_rx_queues; i++)
>-- 
>2.17.0
>

For the rest,

Reviewed-by: Xiaolong Ye <xiaolong.ye@intel.com>
  

Patch

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 458ed58f5..1ed977e9b 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -1065,16 +1065,14 @@  eth_dev_close(struct rte_eth_dev *dev)
 
 	eth_dev_stop(dev);
 
-	rte_vhost_driver_unregister(internal->iface_name);
-
 	list = find_internal_resource(internal->iface_name);
-	if (!list)
-		return;
-
-	pthread_mutex_lock(&internal_list_lock);
-	TAILQ_REMOVE(&internal_list, list, next);
-	pthread_mutex_unlock(&internal_list_lock);
-	rte_free(list);
+	if (list) {
+		rte_vhost_driver_unregister(internal->iface_name);
+		pthread_mutex_lock(&internal_list_lock);
+		TAILQ_REMOVE(&internal_list, list, next);
+		pthread_mutex_unlock(&internal_list_lock);
+		rte_free(list);
+	}
 
 	if (dev->data->rx_queues)
 		for (i = 0; i < dev->data->nb_rx_queues; i++)