diff options
author | Peng Fan <Peng.Fan@freescale.com> | 2015-11-26 10:26:59 +0800 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2015-12-05 18:22:24 -0500 |
commit | 746da1bd42aa5ecc47898399514c9c76d0329706 (patch) | |
tree | 43b3dbb21a9c804bfd52a390aede9bbdc4e203b9 /common | |
parent | 678e9316d48f78d162f705846b6f6eeab4aa5dd0 (diff) | |
download | u-boot-imx-746da1bd42aa5ecc47898399514c9c76d0329706.zip u-boot-imx-746da1bd42aa5ecc47898399514c9c76d0329706.tar.gz u-boot-imx-746da1bd42aa5ecc47898399514c9c76d0329706.tar.bz2 |
common: miiphyutil: avoid memory leak
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>
Diffstat (limited to 'common')
-rw-r--r-- | common/miiphyutil.c | 2 |
1 files changed, 2 insertions, 0 deletions
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; } |