From 30ebd4f6bc83fa4832b658705d4020cb82dfdaea Mon Sep 17 00:00:00 2001 From: Matt Fleming Date: Tue, 27 Nov 2012 16:19:17 +0000 Subject: [PATCH] module: Fix memory leak in spawn_load() If for some reason we fail to load a module then we need to free the memory allocated to that module. Signed-off-by: Matt Fleming --- com32/lib/sys/module/exec.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/com32/lib/sys/module/exec.c b/com32/lib/sys/module/exec.c index 29d0a2f..9ccab36 100644 --- a/com32/lib/sys/module/exec.c +++ b/com32/lib/sys/module/exec.c @@ -194,8 +194,10 @@ int spawn_load(const char *name, int argc, char **argv) return -1; if (get_module_type(module) == EXEC_MODULE) { - if (!argc || !argv || strcmp(argv[0], name)) - return -1; + if (!argc || !argv || strcmp(argv[0], name)) { + res = -1; + goto out; + } } if (!strcmp(cur_module->name, module->name)) { @@ -218,10 +220,8 @@ int spawn_load(const char *name, int argc, char **argv) } res = module_load(module); - if (res != 0) { - _module_unload(module); - return res; - } + if (res != 0) + goto out; type = get_module_type(module); prev_module = cur_module; @@ -259,14 +259,16 @@ int spawn_load(const char *name, int argc, char **argv) cur_module = prev_module; res = module_unload(module); - if (res != 0) { - return res; - } + if (res != 0) + goto out; return ((unsigned int)ret_val & 0xFF); } - return 0; +out: + if (res) + _module_unload(module); + return res; } void exec_term(void) -- 2.7.4