diff --git a/binfmt/elf.c b/binfmt/elf.c index 1a96bea0277..fd75f13ea2a 100644 --- a/binfmt/elf.c +++ b/binfmt/elf.c @@ -270,32 +270,28 @@ static int elf_loadbinary(FAR struct binary_s *binp) * a memory leak? */ -#ifdef CONFIG_ARCH_ADDRENV -# warning "REVISIT" -#else - binp->alloc[0] = (FAR void *)loadinfo.textalloc; -#endif - -#ifdef CONFIG_BINFMT_CONSTRUCTORS - /* Save information about constructors. NOTE: destructors are not - * yet supported. - */ - - binp->alloc[1] = loadinfo.ctoralloc; - binp->ctors = loadinfo.ctors; - binp->nctors = loadinfo.nctors; - - binp->alloc[2] = loadinfo.dtoralloc; - binp->dtors = loadinfo.dtors; - binp->ndtors = loadinfo.ndtors; -#endif - #ifdef CONFIG_ARCH_ADDRENV /* Save the address environment in the binfmt structure. This will be * needed when the module is executed. */ up_addrenv_clone(&loadinfo.addrenv, &binp->addrenv); +#else + binp->alloc[0] = (FAR void *)loadinfo.textalloc; +#ifdef CONFIG_BINFMT_CONSTRUCTORS + binp->alloc[1] = loadinfo.ctoralloc; + binp->alloc[2] = loadinfo.dtoralloc; +#endif +#endif + +#ifdef CONFIG_BINFMT_CONSTRUCTORS + /* Save information about constructors and destructors. */ + + binp->ctors = loadinfo.ctors; + binp->nctors = loadinfo.nctors; + + binp->dtors = loadinfo.dtors; + binp->ndtors = loadinfo.ndtors; #endif elf_dumpentrypt(binp, &loadinfo); diff --git a/binfmt/libelf/libelf_unload.c b/binfmt/libelf/libelf_unload.c index b6af1978cd2..23361fcc205 100644 --- a/binfmt/libelf/libelf_unload.c +++ b/binfmt/libelf/libelf_unload.c @@ -90,23 +90,24 @@ int elf_unload(struct elf_loadinfo_s *loadinfo) /* Release memory used to hold static constructors and destructors */ #ifdef CONFIG_BINFMT_CONSTRUCTORS +#ifndef CONFIG_ARCH_ADDRENV if (loadinfo->ctoralloc != 0) { kumm_free(loadinfo->ctoralloc); - loadinfo->ctoralloc = NULL; } - - loadinfo->ctors = NULL; - loadinfo->nctors = 0; - if (loadinfo->dtoralloc != 0) { kumm_free(loadinfo->dtoralloc); - loadinfo->dtoralloc = NULL; } +#endif - loadinfo->dtors = NULL; - loadinfo->ndtors = 0; + loadinfo->ctoralloc = NULL; + loadinfo->ctors = NULL; + loadinfo->nctors = 0; + + loadinfo->dtoralloc = NULL; + loadinfo->dtors = NULL; + loadinfo->ndtors = 0; #endif return OK;