[syslinux:elflink] module: Fix memory leak in spawn_load()

syslinux-bot for Matt Fleming matt.fleming at intel.com
Tue Nov 27 14:15:05 PST 2012


Commit-ID:  30ebd4f6bc83fa4832b658705d4020cb82dfdaea
Gitweb:     http://www.syslinux.org/commit/30ebd4f6bc83fa4832b658705d4020cb82dfdaea
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Tue, 27 Nov 2012 16:19:17 +0000
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Tue, 27 Nov 2012 21:09:44 +0000

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 <matt.fleming at intel.com>

---
 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)


More information about the Syslinux-commits mailing list