The destroy helper has been reworked to zero all the heap object but
leave the lock untouched. The heap lock is then released through the
standard API.

Signed-off-by: David Marchand <david.march...@redhat.com>
---
Changes since v2:
- shrinked the change to the required part,

---
 lib/eal/common/malloc_heap.c | 6 ++++--
 lib/eal/common/rte_malloc.c  | 5 +----
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
index d7c410b786..d3c474d79c 100644
--- a/lib/eal/common/malloc_heap.c
+++ b/lib/eal/common/malloc_heap.c
@@ -1385,8 +1385,10 @@ malloc_heap_destroy(struct malloc_heap *heap)
        if (heap->total_size != 0)
                RTE_LOG(ERR, EAL, "Total size not zero, heap is likely 
corrupt\n");
 
-       /* after this, the lock will be dropped */
-       memset(heap, 0, sizeof(*heap));
+       /* Reset all of the heap but the (hold) lock so caller can release it. 
*/
+       RTE_BUILD_BUG_ON(offsetof(struct malloc_heap, lock) != 0);
+       memset(RTE_PTR_ADD(heap, sizeof(heap->lock)), 0,
+               sizeof(*heap) - sizeof(heap->lock));
 
        return 0;
 }
diff --git a/lib/eal/common/rte_malloc.c b/lib/eal/common/rte_malloc.c
index d39870bf3c..ebafef3f6c 100644
--- a/lib/eal/common/rte_malloc.c
+++ b/lib/eal/common/rte_malloc.c
@@ -657,10 +657,7 @@ rte_malloc_heap_destroy(const char *heap_name)
        /* sanity checks done, now we can destroy the heap */
        rte_spinlock_lock(&heap->lock);
        ret = malloc_heap_destroy(heap);
-
-       /* if we failed, lock is still active */
-       if (ret < 0)
-               rte_spinlock_unlock(&heap->lock);
+       rte_spinlock_unlock(&heap->lock);
 unlock:
        rte_mcfg_mem_write_unlock();
 
-- 
2.39.2

Reply via email to