public inbox for linux-kernel@vger.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

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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox