Commit 5775f00e1206fd425609c26ee9a3620149e567ac

Authored by Mario Six
Committed by Joe Hershberger
1 parent d38de3380d

net: tsec: Fix memory leak in error path

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>

Showing 1 changed file with 3 additions and 1 deletions Side-by-side Diff

... ... @@ -701,8 +701,10 @@
701 701  
702 702 priv = (struct tsec_private *)malloc(sizeof(*priv));
703 703  
704   - if (!priv)
  704 + if (!priv) {
  705 + free(dev);
705 706 return 0;
  707 + }
706 708  
707 709 priv->regs = tsec_info->regs;
708 710 priv->phyregs_sgmii = tsec_info->miiregs_sgmii;