about summary refs log tree commit diff stats
path: root/src/main.c
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-10-31 15:38:31 +0100
committerptitSeb <sebastien.chev@gmail.com>2023-10-31 15:38:31 +0100
commit362a3fde10a3bb2738fcf30ae2e2eaf4a53df042 (patch)
treeff6233f6cba44c0326cbe366d79fb7a46e1b8d60 /src/main.c
parent5c13f8f10ac82ca642a6c930585989cc0d75a664 (diff)
downloadbox64-362a3fde10a3bb2738fcf30ae2e2eaf4a53df042.tar.gz
box64-362a3fde10a3bb2738fcf30ae2e2eaf4a53df042.zip
[ELFLOADER] Changed how memory is managed in elfloader
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c21
1 files changed, 5 insertions, 16 deletions
diff --git a/src/main.c b/src/main.c
index eb185c66..0d0a61cf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1728,32 +1728,21 @@ int main(int argc, const char **argv, char **env) {
 
     if(CalcLoadAddr(elf_header)) {
         printf_log(LOG_NONE, "Error: reading elf header of %s\n", my_context->fullpath);
-        fclose(f);
-        free_contextargv();
-        FreeBox64Context(&my_context);
-        FreeCollection(&ld_preload);
-        return -1;
-    }
-    // allocate memory
-    if(AllocElfMemory(my_context, elf_header, 1)) {
-        printf_log(LOG_NONE, "Error: allocating memory for elf %s\n", my_context->fullpath);
-        fclose(f);
+        FreeElfHeader(&elf_header);
         free_contextargv();
         FreeBox64Context(&my_context);
         FreeCollection(&ld_preload);
         return -1;
     }
-    // Load elf into memory
-    if(LoadElfMemory(f, my_context, elf_header)) {
-        printf_log(LOG_NONE, "Error: loading in memory elf %s\n", my_context->fullpath);
-        fclose(f);
+    // allocate memory and load elf
+    if(AllocLoadElfMemory(my_context, elf_header, 1)) {
+        printf_log(LOG_NONE, "Error: loading elf %s\n", my_context->fullpath);
+        FreeElfHeader(&elf_header);
         free_contextargv();
         FreeBox64Context(&my_context);
         FreeCollection(&ld_preload);
         return -1;
     }
-    // can close the file now
-    fclose(f);
     if(ElfCheckIfUseTCMallocMinimal(elf_header)) {
         if(!box64_tcmalloc_minimal) {
             // need to reload with tcmalloc_minimal as a LD_PRELOAD!