[dpdk-dev] librte_pmd_fm10k: Set pointer to NULL after free

Message ID 1425628607-1497-1-git-send-email-michael.qiu@intel.com (mailing list archive)
State Accepted, archived
Headers

Commit Message

Michael Qiu March 6, 2015, 7:56 a.m. UTC
  It could be a potential not safe issue.

Signed-off-by: Michael Qiu <michael.qiu@intel.com>
---
 lib/librte_pmd_fm10k/fm10k_ethdev.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
  

Comments

Chen, Jing D March 16, 2015, 1:46 a.m. UTC | #1
> -----Original Message-----
> From: Qiu, Michael
> Sent: Friday, March 06, 2015 3:57 PM
> To: dev@dpdk.org
> Cc: Chen, Jing D; Qiu, Michael
> Subject: [PATCH] librte_pmd_fm10k: Set pointer to NULL after free
> 
> It could be a potential not safe issue.
> 
> Signed-off-by: Michael Qiu <michael.qiu@intel.com>
> ---
>  lib/librte_pmd_fm10k/fm10k_ethdev.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/librte_pmd_fm10k/fm10k_ethdev.c
> b/lib/librte_pmd_fm10k/fm10k_ethdev.c
> index 07ea1e7..30962d3 100644
> --- a/lib/librte_pmd_fm10k/fm10k_ethdev.c
> +++ b/lib/librte_pmd_fm10k/fm10k_ethdev.c
> @@ -142,9 +142,12 @@ rx_queue_free(struct fm10k_rx_queue *q)
>  	if (q) {
>  		PMD_INIT_LOG(DEBUG, "Freeing rx queue %p", q);
>  		rx_queue_clean(q);
> -		if (q->sw_ring)
> +		if (q->sw_ring) {
>  			rte_free(q->sw_ring);
> +			q->sw_ring = NULL;
> +		}
>  		rte_free(q);
> +		q = NULL;
>  	}
>  }
> 
> @@ -225,11 +228,16 @@ tx_queue_free(struct fm10k_tx_queue *q)
>  	if (q) {
>  		PMD_INIT_LOG(DEBUG, "Freeing tx queue %p", q);
>  		tx_queue_clean(q);
> -		if (q->rs_tracker.list)
> +		if (q->rs_tracker.list) {
>  			rte_free(q->rs_tracker.list);
> -		if (q->sw_ring)
> +			q->rs_tracker.list = NULL;
> +		}
> +		if (q->sw_ring) {
>  			rte_free(q->sw_ring);
> +			q->sw_ring = NULL;
> +		}
>  		rte_free(q);
> +		q = NULL;
>  	}
>  }
> 
> --
> 1.9.3

Acked-by: Jing Chen <jing.d.chen@intel.com>
  
Thomas Monjalon March 16, 2015, 11:42 p.m. UTC | #2
> > It could be a potential not safe issue.
> > 
> > Signed-off-by: Michael Qiu <michael.qiu@intel.com>
> 
> Acked-by: Jing Chen <jing.d.chen@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_pmd_fm10k/fm10k_ethdev.c b/lib/librte_pmd_fm10k/fm10k_ethdev.c
index 07ea1e7..30962d3 100644
--- a/lib/librte_pmd_fm10k/fm10k_ethdev.c
+++ b/lib/librte_pmd_fm10k/fm10k_ethdev.c
@@ -142,9 +142,12 @@  rx_queue_free(struct fm10k_rx_queue *q)
 	if (q) {
 		PMD_INIT_LOG(DEBUG, "Freeing rx queue %p", q);
 		rx_queue_clean(q);
-		if (q->sw_ring)
+		if (q->sw_ring) {
 			rte_free(q->sw_ring);
+			q->sw_ring = NULL;
+		}
 		rte_free(q);
+		q = NULL;
 	}
 }
 
@@ -225,11 +228,16 @@  tx_queue_free(struct fm10k_tx_queue *q)
 	if (q) {
 		PMD_INIT_LOG(DEBUG, "Freeing tx queue %p", q);
 		tx_queue_clean(q);
-		if (q->rs_tracker.list)
+		if (q->rs_tracker.list) {
 			rte_free(q->rs_tracker.list);
-		if (q->sw_ring)
+			q->rs_tracker.list = NULL;
+		}
+		if (q->sw_ring) {
 			rte_free(q->sw_ring);
+			q->sw_ring = NULL;
+		}
 		rte_free(q);
+		q = NULL;
 	}
 }