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

Hal Rosenstock halr at voltaire.com
Wed Nov 3 06:06:28 PST 2004


On Tue, 2004-11-02 at 23:00, Shirley Ma wrote:
> Here is the patch. Please review it.

Yes, these are memory leaks in agent_mad_send but it would be better to
fix them with the deallocation being done at the function level where
the allocation is done. Hence rather than agent_send_mad returning void,
it should return int, etc. I will post a patch for this shortly.

-- Hal

> 
> 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);
> 
> 




More information about the general mailing list