aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--com32/lib/sys/module/common.c8
-rw-r--r--com32/lib/sys/module/elf_module.c6
-rw-r--r--com32/lib/sys/module/exec.c4
-rw-r--r--com32/lib/sys/module/shallow_module.c6
4 files changed, 20 insertions, 4 deletions
diff --git a/com32/lib/sys/module/common.c b/com32/lib/sys/module/common.c
index 7c588ef7..8a685130 100644
--- a/com32/lib/sys/module/common.c
+++ b/com32/lib/sys/module/common.c
@@ -335,10 +335,12 @@ int module_unload(struct elf_module *module) {
list_del_init(&module->list);
// Release the loaded segments or sections
- elf_free(module->module_addr);
+ if (module->module_addr != NULL) {
+ elf_free(module->module_addr);
- DBG_PRINT("%s MODULE %s UNLOADED\n", module->shallow ? "SHALLOW" : "",
- module->name);
+ DBG_PRINT("%s MODULE %s UNLOADED\n", module->shallow ? "SHALLOW" : "",
+ module->name);
+ }
// Release the module structure
free(module);
diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c
index 0adba718..58f94d04 100644
--- a/com32/lib/sys/module/elf_module.c
+++ b/com32/lib/sys/module/elf_module.c
@@ -416,6 +416,12 @@ int module_load(struct elf_module *module) {
int res;
Elf32_Ehdr elf_hdr;
+ // Do not allow duplicate modules
+ if (module_find(module->name) != NULL) {
+ DBG_PRINT("Module already loaded.\n");
+ return -1;
+ }
+
// Get a mapping/copy of the ELF file in memory
res = image_load(module);
diff --git a/com32/lib/sys/module/exec.c b/com32/lib/sys/module/exec.c
index 025864bc..bb855efb 100644
--- a/com32/lib/sys/module/exec.c
+++ b/com32/lib/sys/module/exec.c
@@ -65,6 +65,7 @@ int load_library(const char *name) {
if (res != 0) {
+ module_unload(module);
return res;
}
@@ -106,7 +107,7 @@ int unload_library(const char *name) {
}
int spawnv(const char *name, const char **argv) {
- int res, ret_val;
+ int res, ret_val = 0;
struct elf_module *module = module_alloc(module_get_fullname(name));
@@ -116,6 +117,7 @@ int spawnv(const char *name, const char **argv) {
res = module_load(module);
if (res != 0) {
+ module_unload(module);
return res;
}
diff --git a/com32/lib/sys/module/shallow_module.c b/com32/lib/sys/module/shallow_module.c
index 1b76aaae..ed196cd9 100644
--- a/com32/lib/sys/module/shallow_module.c
+++ b/com32/lib/sys/module/shallow_module.c
@@ -118,6 +118,12 @@ int module_load_shallow(struct elf_module *module) {
int res;
Elf32_Ehdr elf_hdr;
+ // Do not allow duplicate modules
+ if (module_find(module->name) != NULL) {
+ DBG_PRINT("Module already loaded.\n");
+ return -1;
+ }
+
res = image_load(module);
if (res < 0)