[openib-general] [PATCH] fix memory leak problem in agent_mad_send()

Shirley Ma mashirle at us.ibm.com
Tue Nov 2 20:00:09 PST 2004


Here is the patch. Please review it.

diff -urN access/agent.c access.patch5/agent.c
--- access/agent.c	2004-11-02 17:40:06.000000000 -0800
+++ access.patch5/agent.c	2004-11-02 18:43:47.534608536 -0800
@@ -357,12 +357,16 @@
 	if (!port_priv) {
 		printk(KERN_ERR SPFX "agent_mad_send: no matching MAD agent %p\n",
 		       mad_agent);
+		kfree(mad);
 		return;
 	}
 
 	agent_send_wr = kmalloc(sizeof(*agent_send_wr), GFP_KERNEL);
-	if (!agent_send_wr)
+	if (!agent_send_wr) {
+		printk(KERN_ERR SPFX "No memory for agent work request\n");
+		kfree(mad);
 		return;
+	}
 	agent_send_wr->mad = mad;
 
 	/* PCI mapping */
@@ -407,6 +411,7 @@
 	if (IS_ERR(agent_send_wr->ah)) {
 		printk(KERN_ERR SPFX "No memory for address handle\n");
 		kfree(mad);
+		kfree(agent_send_wr);
 		return;
 	}
                                                                                 
@@ -432,6 +437,8 @@
 				 sizeof(struct ib_mad),
 				 PCI_DMA_TODEVICE);
 		ib_destroy_ah(agent_send_wr->ah);
+		kfree(mad);
+		kfree(agent_send_wr);
 	} else {
 		list_add_tail(&agent_send_wr->send_list,
 			      &port_priv->send_posted_list);



-- 
Thanks
Shirley Ma
IBM Linux Technology Center



More information about the general mailing list