Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH] RDMA/cm: Fix memory leak in ib_cm_insert_listen
@ 2022-06-21  5:25 Miaoqian Lin
  2022-06-24 19:44 ` Jason Gunthorpe
  0 siblings, 1 reply; 2+ messages in thread
From: Miaoqian Lin @ 2022-06-21  5:25 UTC (permalink / raw)
  To: Jason Gunthorpe, Leon Romanovsky, Mark Zhang, Maor Gottlieb,
	Weihang Li, Wenpeng Liang, linux-rdma, linux-kernel
  Cc: linmq006

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")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/infiniband/core/cm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index 1c107d6d03b9..b985e0d9bc05 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-24 19:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-21  5:25 [PATCH] RDMA/cm: Fix memory leak in ib_cm_insert_listen Miaoqian Lin
2022-06-24 19:44 ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox