Re: [2.6.31] Memory leak in load_module()?

Rusty Russell
2009-09-22T02:30:28Z

On Fri, 11 Sep 2009 05:08:46 pm Tetsuo Handa wrote:
> Is this real memory leak?

Yep.

God, this code is a turd. This should fix it though:

diff --git a/kernel/module.c b/kernel/module.c
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1907,6 +1924,17 @@ static void setup_modinfo(struct module
}
}

+static void free_modinfo(struct module *mod)
+{
+ struct module_attribute *attr;
+ int i;
+
+ for (i = 0; (attr = modinfo_attrs[i]); i++) {
+ if (attr->free)
+ attr->free(mod);
+ }
+}
+
#ifdef CONFIG_KALLSYMS

/* lookup symbol in given range of kernel_symbols */
@@ -2632,6 +2662,7 @@ static noinline struct module *load_modu
synchronize_sched();
module_arch_cleanup(mod);
cleanup:
+ free_modinfo(mod);
kobject_del(&mod->mkobj.kobj);
kobject_put(&mod->mkobj.kobj);