From: Rusty Russell Date: Fri, 25 Sep 2009 06:32:58 +0000 (-0600) Subject: module: fix memory leak when load fails after srcversion/version allocated X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a263f7763c364015f92e7c097fa46c6673f6fcb0;p=GitHub%2Fmt8127%2Fandroid_kernel_alcatel_ttab.git module: fix memory leak when load fails after srcversion/version allocated Normally the twisty paths of sysfs will free the attributes, but not if we fail before we hook it into sysfs (which is the last thing we do in load_module). (This sysfs code is a turd, no doubt there are other issues lurking too). Reported-by: Tetsuo Handa Signed-off-by: Rusty Russell Cc: Catalin Marinas Tested-by: Tetsuo Handa --- diff --git a/kernel/module.c b/kernel/module.c index 39827c3d9484..c54f10d90e1c 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -1797,6 +1797,17 @@ static void setup_modinfo(struct module *mod, Elf_Shdr *sechdrs, } } +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 */ @@ -2506,6 +2517,7 @@ static noinline struct module *load_module(void __user *umod, synchronize_sched(); module_arch_cleanup(mod); cleanup: + free_modinfo(mod); kobject_del(&mod->mkobj.kobj); kobject_put(&mod->mkobj.kobj); free_unload: