diff mbox series

[U-Boot,v2,23/78] net: tsec: Fix memory leak in error path

Message ID 20171213071946.6181-23-mario.six@gdsys.cc
State Superseded, archived
Delegated to: Mario Six
Headers show
Series [U-Boot,v2,01/78] mpc8308rdb: Fix style violation | expand

Commit Message

Mario Six Dec. 13, 2017, 7:18 a.m. UTC
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>
---

v1 -> v2:
None

---
 drivers/net/tsec.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--
2.13.6

Comments

Joe Hershberger Jan. 3, 2018, 2:34 p.m. UTC | #1
On Wed, Dec 13, 2017 at 1:18 AM, Mario Six <mario.six@gdsys.cc> wrote:
> 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>
diff mbox series

Patch

diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c
index 071595218e..44140fb037 100644
--- a/drivers/net/tsec.c
+++ b/drivers/net/tsec.c
@@ -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;