When using the ring to find out tailq entry, however it had been
freed by rte_memzone_free function. This change prevents that
from happening.

Fixes: 4e32101f9b01 ("ring: support freeing")
Cc: sta...@dpdk.org

Signed-off-by: Yunjian Wang <wangyunj...@huawei.com>
---
 lib/ring/rte_ring.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/lib/ring/rte_ring.c b/lib/ring/rte_ring.c
index 8ed455043d..17d2d7f8a8 100644
--- a/lib/ring/rte_ring.c
+++ b/lib/ring/rte_ring.c
@@ -333,11 +333,6 @@ rte_ring_free(struct rte_ring *r)
                return;
        }
 
-       if (rte_memzone_free(r->memzone) != 0) {
-               RTE_LOG(ERR, RING, "Cannot free memory\n");
-               return;
-       }
-
        ring_list = RTE_TAILQ_CAST(rte_ring_tailq.head, rte_ring_list);
        rte_mcfg_tailq_write_lock();
 
@@ -349,7 +344,7 @@ rte_ring_free(struct rte_ring *r)
 
        if (te == NULL) {
                rte_mcfg_tailq_write_unlock();
-               return;
+               goto free_memzone;
        }
 
        TAILQ_REMOVE(ring_list, te, next);
@@ -357,6 +352,10 @@ rte_ring_free(struct rte_ring *r)
        rte_mcfg_tailq_write_unlock();
 
        rte_free(te);
+
+free_memzone:
+       if (rte_memzone_free(r->memzone) != 0)
+               RTE_LOG(ERR, RING, "Cannot free memory\n");
 }
 
 /* dump the status of the ring on the console */
-- 
2.33.0

Reply via email to