binfmt/: If there is an address environment (CONFIG_ARCH_ADDRENV), binfmt/elf doesn't need to free ctor/dtor alloc since freeing the address environment releases the heap automatically.

This commit is contained in:
Xiang Xiao
2019-01-26 11:29:08 -06:00
committed by Gregory Nutt
parent 38ffb98f1b
commit 264a7164bc
2 changed files with 25 additions and 28 deletions

View File

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

View File

@@ -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;