]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
net: tsec: Fix memory leak in error path
authorMario Six <mario.six@gdsys.cc>
Mon, 15 Jan 2018 10:08:22 +0000 (11:08 +0100)
committerJoe Hershberger <joe.hershberger@ni.com>
Mon, 26 Feb 2018 21:28:43 +0000 (15:28 -0600)
tsec_initialize allocates a private driver structure using malloc.
Should the memory allocation of this private structure fail, the
function execution is aborted with a return 0, but the previously
allocated device structure is never freed, hence leaked.

Free the device structure in the error case.

Signed-off-by: Mario Six <mario.six@gdsys.cc>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
drivers/net/tsec.c

index 071595218e9737ae472285e5b7871fcc82ed5694..44140fb0374b636f2b2884447cc1020abaf9b808 100644 (file)
@@ -701,8 +701,10 @@ static int tsec_initialize(bd_t *bis, struct tsec_info_struct *tsec_info)
 
        priv = (struct tsec_private *)malloc(sizeof(*priv));
 
-       if (!priv)
+       if (!priv) {
+               free(dev);
                return 0;
+       }
 
        priv->regs = tsec_info->regs;
        priv->phyregs_sgmii = tsec_info->miiregs_sgmii;