From: Peng Fan Date: Thu, 26 Nov 2015 02:26:59 +0000 (+0800) Subject: common: miiphyutil: avoid memory leak X-Git-Url: http://git.dujemihanovic.xyz/login.html?a=commitdiff_plain;h=746da1bd42aa5ecc47898399514c9c76d0329706;p=u-boot.git 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 Cc: Joe Hershberger Cc: Simon Glass Cc: Bin Meng Reviewed-by: Bin Meng Acked-by: Joe Hershberger --- diff --git a/common/miiphyutil.c b/common/miiphyutil.c index 0811e098b4..7e41957185 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; }