Re: [U-Boot] [PATCH 1/1] ubifs: no NULL check needed before free
On 11/21/2017 10:20 AM, Alex Sadovsky wrote: Hi Heinrich and Heiko, do you see anything strange in this code (it was more obvious before the patch but it can still be spotted)? I should say that it's too late to check for "file != NULL" after the "file->private_data" dereference. Maybe it should look like this: if (file) kfree(file->private_data); free(file); shouldn't it? Thanks for spotting this. Probably we should fix it here: if (!file || !dentry || !dir) { printf("%s: Error, no memory for malloc!\n", __func__); err = -ENOMEM; goto out; } Why should we first print printf("%s: Error, no memory for malloc!\n", __func__); and then dbg_gen("cannot find next direntry, error %d", err); Instead we should immediately return. Regards Heinrich ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH 1/1] ubifs: no NULL check needed before free
Hi Heinrich and Heiko, do you see anything strange in this code (it was more obvious before the patch but it can still be spotted)? I should say that it's too late to check for "file != NULL" after the "file->private_data" dereference. Maybe it should look like this: if (file) kfree(file->private_data); free(file); shouldn't it? Cheers, Alex. ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
Re: [U-Boot] [PATCH 1/1] ubifs: no NULL check needed before free
Hello Heinrich, Am 08.11.2017 um 22:28 schrieb Heinrich Schuchardt: kfree() calls free. free() checks if the parameter is NULL. Signed-off-by: Heinrich Schuchardt--- fs/ubifs/ubifs.c | 12 1 file changed, 4 insertions(+), 8 deletions(-) applied to u-boot-ubi master Thanks! bye, Heiko -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: h...@denx.de ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot
[U-Boot] [PATCH 1/1] ubifs: no NULL check needed before free
kfree() calls free. free() checks if the parameter is NULL. Signed-off-by: Heinrich Schuchardt--- fs/ubifs/ubifs.c | 12 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c index 8f1c9d167d..4465523d5f 100644 --- a/fs/ubifs/ubifs.c +++ b/fs/ubifs/ubifs.c @@ -462,14 +462,10 @@ out: dbg_gen("cannot find next direntry, error %d", err); out_free: - if (file->private_data) - kfree(file->private_data); - if (file) - free(file); - if (dentry) - free(dentry); - if (dir) - free(dir); + kfree(file->private_data); + free(file); + free(dentry); + free(dir); return ret; } -- 2.14.2 ___ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot