lkml.org 
[lkml]   [2014]   [Jun]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Fix memory leak in cm.c
On 6/15/2014 9:26 PM, Nick wrote:
> This patch fixes memory by checking in function,
> *get_skuff if it is be passing a Null skb
> struct.
> Cheers Nick
> Signed-off-by: Nick <xerofoify@gmail.com>
> ---
> drivers/infiniband/hw/cxgb4/cm.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
> index 5e153f6..f9477e2 100644
> --- a/drivers/infiniband/hw/cxgb4/cm.c
> +++ b/drivers/infiniband/hw/cxgb4/cm.c
> @@ -340,7 +340,11 @@ static int status2errno(int status)
> */
> static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
> {
> - if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
> + if (!skb) {
> + return NULL;
> + }
> +
> + else if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
> skb_trim(skb, 0);
> skb_get(skb);
> skb_reset_transport_header(skb);

This patch is incorrect. If skb is null, then get_skb() will allocate a
new one. The idea is to reuse skb if it can be reused (ie is linear and
not cloned). Otherwise allocate a new one:

static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
{
if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
skb_trim(skb, 0);
skb_get(skb);
skb_reset_transport_header(skb);
} else {
skb = alloc_skb(len, gfp);
}
t4_set_arp_err_handler(skb, NULL, NULL);
return skb;
}


However, if skb is not null and (is not linear or is cloned), then we
leak the skb. So there is a bug.

So the else clause should free skb if it not NULL before calling
alloc_skb() to get a new one.

Steve.



\
 
 \ /
  Last update: 2014-06-16 16:21    [W:0.042 / U:1.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site