All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] common: miiphyutil: avoid memory leak
@ 2015-11-26  2:26 Peng Fan
  2015-11-26  2:33 ` Bin Meng
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Peng Fan @ 2015-11-26  2:26 UTC (permalink / raw)
  To: u-boot

The following code will alloc memory for new_dev and ldev:
"
new_dev = mdio_alloc();
ldev = malloc(sizeof(*ldev));
"
Either new_dev or ldev is NULL, directly return, but this may leak memory.
So before return, using free(ldev) and mdio_free(new_dev) to avoid
leaking memory, also free can handle NULL pointer.

Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
---
 common/miiphyutil.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/common/miiphyutil.c b/common/miiphyutil.c
index 0811e09..7e41957 100644
--- a/common/miiphyutil.c
+++ b/common/miiphyutil.c
@@ -114,6 +114,8 @@ void miiphy_register(const char *name,
 	if (new_dev == NULL || ldev == NULL) {
 		printf("miiphy_register: cannot allocate memory for '%s'\n",
 			name);
+		free(ldev);
+		mdio_free(new_dev);
 		return;
 	}
 
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH] common: miiphyutil: avoid memory leak
  2015-11-26  2:26 [U-Boot] [PATCH] common: miiphyutil: avoid memory leak Peng Fan
@ 2015-11-26  2:33 ` Bin Meng
  2015-11-30 20:34 ` Joe Hershberger
  2015-12-06 22:06 ` [U-Boot] " Tom Rini
  2 siblings, 0 replies; 4+ messages in thread
From: Bin Meng @ 2015-11-26  2:33 UTC (permalink / raw)
  To: u-boot

On Thu, Nov 26, 2015 at 10:26 AM, Peng Fan <Peng.Fan@freescale.com> wrote:
> The following code will alloc memory for new_dev and ldev:
> "
> new_dev = mdio_alloc();
> ldev = malloc(sizeof(*ldev));
> "
> Either new_dev or ldev is NULL, directly return, but this may leak memory.
> So before return, using free(ldev) and mdio_free(new_dev) to avoid
> leaking memory, also free can handle NULL pointer.
>
> Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Bin Meng <bmeng.cn@gmail.com>
> ---
>  common/miiphyutil.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/common/miiphyutil.c b/common/miiphyutil.c
> index 0811e09..7e41957 100644
> --- a/common/miiphyutil.c
> +++ b/common/miiphyutil.c
> @@ -114,6 +114,8 @@ void miiphy_register(const char *name,
>         if (new_dev == NULL || ldev == NULL) {
>                 printf("miiphy_register: cannot allocate memory for '%s'\n",
>                         name);
> +               free(ldev);
> +               mdio_free(new_dev);
>                 return;
>         }
>
> --

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH] common: miiphyutil: avoid memory leak
  2015-11-26  2:26 [U-Boot] [PATCH] common: miiphyutil: avoid memory leak Peng Fan
  2015-11-26  2:33 ` Bin Meng
@ 2015-11-30 20:34 ` Joe Hershberger
  2015-12-06 22:06 ` [U-Boot] " Tom Rini
  2 siblings, 0 replies; 4+ messages in thread
From: Joe Hershberger @ 2015-11-30 20:34 UTC (permalink / raw)
  To: u-boot

Hi Peng

On Wed, Nov 25, 2015 at 8:26 PM, Peng Fan <Peng.Fan@freescale.com> wrote:
> The following code will alloc memory for new_dev and ldev:
> "
> new_dev = mdio_alloc();
> ldev = malloc(sizeof(*ldev));
> "
> Either new_dev or ldev is NULL, directly return, but this may leak memory.
> So before return, using free(ldev) and mdio_free(new_dev) to avoid
> leaking memory, also free can handle NULL pointer.
>
> Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Bin Meng <bmeng.cn@gmail.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] common: miiphyutil: avoid memory leak
  2015-11-26  2:26 [U-Boot] [PATCH] common: miiphyutil: avoid memory leak Peng Fan
  2015-11-26  2:33 ` Bin Meng
  2015-11-30 20:34 ` Joe Hershberger
@ 2015-12-06 22:06 ` Tom Rini
  2 siblings, 0 replies; 4+ messages in thread
From: Tom Rini @ 2015-12-06 22:06 UTC (permalink / raw)
  To: u-boot

On Thu, Nov 26, 2015 at 10:26:59AM +0800, Peng Fan wrote:

> The following code will alloc memory for new_dev and ldev:
> "
> new_dev = mdio_alloc();
> ldev = malloc(sizeof(*ldev));
> "
> Either new_dev or ldev is NULL, directly return, but this may leak memory.
> So before return, using free(ldev) and mdio_free(new_dev) to avoid
> leaking memory, also free can handle NULL pointer.
> 
> Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Bin Meng <bmeng.cn@gmail.com>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
> Acked-by: Joe Hershberger <joe.hershberger@ni.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151206/d3298017/attachment.sig>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-12-06 22:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-26  2:26 [U-Boot] [PATCH] common: miiphyutil: avoid memory leak Peng Fan
2015-11-26  2:33 ` Bin Meng
2015-11-30 20:34 ` Joe Hershberger
2015-12-06 22:06 ` [U-Boot] " Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.