Skip to contentSkip to conversation

RDMA/cm: Fix memory leak in ib_cm_insert_listen

PATCH Applied Miaoqian Lin 2 participants 2 messages Jun 21, 2022 – Jun 24, 2022 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/cm: Fix memory leak in ib_cm_insert_listen

cm_alloc_id_priv() allocates resource for cm_id_priv. when cm_init_listen() fails, it doesn't free it, leading to memory leak. call ib_destroy_cm_id() to fix this.

Fixes 98f67156a80f ("RDMA/cm: Simplify establishing a listen cm_id")
---
 drivers/infiniband/core/cm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/infiniband/core/cm.c +3 -1
index 1c107d6d03b9..b985e0d9bc05 100644
@@ -1252,8 +1252,10 @@ struct ib_cm_id *ib_cm_insert_listen(struct ib_device *device,
 		return ERR_CAST(cm_id_priv);
 
 	err = cm_init_listen(cm_id_priv, service_id, 0);
-	if (err)
+	if (err) {
+		ib_destroy_cm_id(&cm_id_priv->id);
 		return ERR_PTR(err);
+	}
 
 	spin_lock_irq(&cm_id_priv->lock);
 	listen_id_priv = cm_insert_listen(cm_id_priv, cm_handler);
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 9 lines · Miaoqian Lin

cm_alloc_id_priv() allocates resource for cm_id_priv. when cm_init_listen() fails, it doesn't free it, leading to memory leak. call ib_destroy_cm_id() to fix this.

Fixes 98f67156a80f ("RDMA/cm: Simplify establishing a listen cm_id")
---
 drivers/infiniband/core/cm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Applied to for-rc, thanks

Jason