Patchwork caif: fix cfcnfg_add_phy_layer() leaks

login
register
mail settings
Submitter Jesper Juhl
Date Oct. 24, 2011, 10:01 p.m.
Message ID <alpine.LNX.2.00.1110242359160.19795@swampdragon.chaosbits.net>
Download mbox | patch
Permalink /patch/121428/
State Not Applicable
Delegated to: David Miller
Headers show

Comments

Jesper Juhl - Oct. 24, 2011, 10:01 p.m.
There are two locations where we 'goto out' after having allocated
memory for 'phyinfo' but have not yet assigned it to anything. At the
'out:' label we'll exit from the function and 'phyinfo' will go out of
scope and thus we leak the memory we allocated.

This patch frees the memory before jumping to 'out:', thus fixing the
leaks.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 net/caif/cfcnfg.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

 compile tested only.
David Miller - Oct. 24, 2011, 10:36 p.m.
From: Jesper Juhl <jj@chaosbits.net>
Date: Tue, 25 Oct 2011 00:01:00 +0200 (CEST)

> There are two locations where we 'goto out' after having allocated
> memory for 'phyinfo' but have not yet assigned it to anything. At the
> 'out:' label we'll exit from the function and 'phyinfo' will go out of
> scope and thus we leak the memory we allocated.
> 
> This patch frees the memory before jumping to 'out:', thus fixing the
> leaks.
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>

The code in net-next looks a lot different, please see if the issue
still exists there and resubmit if so, thanks!
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/net/caif/cfcnfg.c b/net/caif/cfcnfg.c
index 52fe33b..b25dc02 100644
--- a/net/caif/cfcnfg.c
+++ b/net/caif/cfcnfg.c
@@ -499,6 +499,7 @@  got_phyid:
 		    cfserl_create(CFPHYTYPE_FRAG, phyid, stx);
 		if (!phy_driver) {
 			pr_warn("Out of memory\n");
+			kfree(phyinfo);
 			goto out;
 		}
 		break;
@@ -506,6 +507,7 @@  got_phyid:
 		phy_driver = NULL;
 		break;
 	default:
+		kfree(phyinfo);
 		goto out;
 	}
 	phy_layer->id = phyid;