All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kernel/module: Fix memleak in module_add_modinfo_attrs()
@ 2019-12-28 11:54 YueHaibing
  2020-01-08  8:05 ` Miroslav Benes
  2020-01-08 16:24 ` Jessica Yu
  0 siblings, 2 replies; 3+ messages in thread
From: YueHaibing @ 2019-12-28 11:54 UTC (permalink / raw)
  To: jeyu, mbenes, yuehaibing; +Cc: linux-kernel

In module_add_modinfo_attrs() if sysfs_create_file() fails
on the first iteration of the loop (so i = 0), we forget to
free the modinfo_attrs.

Fixes: bc6f2a757d52 ("kernel/module: Fix mem leak in module_add_modinfo_attrs")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 kernel/module.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/module.c b/kernel/module.c
index c3770b2..8ec670e 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1784,6 +1784,8 @@ static int module_add_modinfo_attrs(struct module *mod)
 error_out:
 	if (i > 0)
 		module_remove_modinfo_attrs(mod, --i);
+	else
+		kfree(mod->modinfo_attrs);
 	return error;
 }
 
-- 
2.7.4



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

* Re: [PATCH] kernel/module: Fix memleak in module_add_modinfo_attrs()
  2019-12-28 11:54 [PATCH] kernel/module: Fix memleak in module_add_modinfo_attrs() YueHaibing
@ 2020-01-08  8:05 ` Miroslav Benes
  2020-01-08 16:24 ` Jessica Yu
  1 sibling, 0 replies; 3+ messages in thread
From: Miroslav Benes @ 2020-01-08  8:05 UTC (permalink / raw)
  To: YueHaibing; +Cc: jeyu, linux-kernel

On Sat, 28 Dec 2019, YueHaibing wrote:

> In module_add_modinfo_attrs() if sysfs_create_file() fails
> on the first iteration of the loop (so i = 0), we forget to
> free the modinfo_attrs.
> 
> Fixes: bc6f2a757d52 ("kernel/module: Fix mem leak in module_add_modinfo_attrs")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>

Reviewed-by: Miroslav Benes <mbenes@suse.cz>

M

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

* Re: [PATCH] kernel/module: Fix memleak in module_add_modinfo_attrs()
  2019-12-28 11:54 [PATCH] kernel/module: Fix memleak in module_add_modinfo_attrs() YueHaibing
  2020-01-08  8:05 ` Miroslav Benes
@ 2020-01-08 16:24 ` Jessica Yu
  1 sibling, 0 replies; 3+ messages in thread
From: Jessica Yu @ 2020-01-08 16:24 UTC (permalink / raw)
  To: YueHaibing; +Cc: mbenes, linux-kernel

+++ YueHaibing [28/12/19 19:54 +0800]:
>In module_add_modinfo_attrs() if sysfs_create_file() fails
>on the first iteration of the loop (so i = 0), we forget to
>free the modinfo_attrs.
>
>Fixes: bc6f2a757d52 ("kernel/module: Fix mem leak in module_add_modinfo_attrs")
>Signed-off-by: YueHaibing <yuehaibing@huawei.com>

Applied, thanks!

Jessica

>---
> kernel/module.c | 2 ++
> 1 file changed, 2 insertions(+)
>
>diff --git a/kernel/module.c b/kernel/module.c
>index c3770b2..8ec670e 100644
>--- a/kernel/module.c
>+++ b/kernel/module.c
>@@ -1784,6 +1784,8 @@ static int module_add_modinfo_attrs(struct module *mod)
> error_out:
> 	if (i > 0)
> 		module_remove_modinfo_attrs(mod, --i);
>+	else
>+		kfree(mod->modinfo_attrs);
> 	return error;
> }
>
>-- 
>2.7.4
>
>

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

end of thread, other threads:[~2020-01-08 16:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-28 11:54 [PATCH] kernel/module: Fix memleak in module_add_modinfo_attrs() YueHaibing
2020-01-08  8:05 ` Miroslav Benes
2020-01-08 16:24 ` Jessica Yu

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.