[v2,1/2] net/mana: fix memory leak on MR variable allocation
Checks
Commit Message
From: Long Li <longli@microsoft.com>
Use a MR on the stack instead of allocating it. This fixes the memory
leak in the code where a MR is allocated but never freed.
Fixes: 0f5db3c68ba7 ("net/mana: implement memory registration")
Cc: stable@dpdk.org
Signed-off-by: Long Li <longli@microsoft.com>
---
Change in v2:
change commit message to indicate this is a fix. added "Fixes" tag.
drivers/net/mana/mr.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
Comments
On 2/9/2024 12:05 AM, longli@linuxonhyperv.com wrote:
> From: Long Li <longli@microsoft.com>
>
> Use a MR on the stack instead of allocating it. This fixes the memory
> leak in the code where a MR is allocated but never freed.
>
> Fixes: 0f5db3c68ba7 ("net/mana: implement memory registration")
> Cc: stable@dpdk.org
>
> Signed-off-by: Long Li <longli@microsoft.com>
>
Series applied to dpdk-next-net/main, thanks.
@@ -40,7 +40,7 @@ mana_new_pmd_mr(struct mana_mr_btree *local_tree, struct mana_priv *priv,
struct ibv_mr *ibv_mr;
struct mana_range ranges[pool->nb_mem_chunks];
uint32_t i;
- struct mana_mr_cache *mr;
+ struct mana_mr_cache mr;
int ret;
rte_mempool_mem_iter(pool, mana_mempool_chunk_cb, ranges);
@@ -75,14 +75,13 @@ mana_new_pmd_mr(struct mana_mr_btree *local_tree, struct mana_priv *priv,
DP_LOG(DEBUG, "MR lkey %u addr %p len %zu",
ibv_mr->lkey, ibv_mr->addr, ibv_mr->length);
- mr = rte_calloc("MANA MR", 1, sizeof(*mr), 0);
- mr->lkey = ibv_mr->lkey;
- mr->addr = (uintptr_t)ibv_mr->addr;
- mr->len = ibv_mr->length;
- mr->verb_obj = ibv_mr;
+ mr.lkey = ibv_mr->lkey;
+ mr.addr = (uintptr_t)ibv_mr->addr;
+ mr.len = ibv_mr->length;
+ mr.verb_obj = ibv_mr;
rte_spinlock_lock(&priv->mr_btree_lock);
- ret = mana_mr_btree_insert(&priv->mr_btree, mr);
+ ret = mana_mr_btree_insert(&priv->mr_btree, &mr);
rte_spinlock_unlock(&priv->mr_btree_lock);
if (ret) {
ibv_dereg_mr(ibv_mr);
@@ -90,7 +89,7 @@ mana_new_pmd_mr(struct mana_mr_btree *local_tree, struct mana_priv *priv,
return ret;
}
- ret = mana_mr_btree_insert(local_tree, mr);
+ ret = mana_mr_btree_insert(local_tree, &mr);
if (ret) {
/* Don't need to clean up MR as it's already
* in the global tree