binfmt/nxflat.c: Update to last NxFLAT change: The logic must respect the reference count before freeing the dspace memory region.

This commit is contained in:
Gregory Nutt 2019-03-12 09:42:04 -06:00
parent ba8714daac
commit 622202da20
2 changed files with 20 additions and 10 deletions

View File

@ -246,18 +246,28 @@ static int nxflat_unloadbinary(FAR struct binary_s *binp)
if (dspace != NULL)
{
/* Free dspace region */
/* Check if this is the last reference to dspace. It may still be
* needed by other threads. In that case, it must persist after this
* thread terminates.
*/
kumm_free(dspace->region);
dspace->region = 0;
if (dspace->crefs == 1)
{
/* Free the dspace region */
kumm_free(dspace->region);
dspace->region = NULL;
/* Mark alloc[0] (dspace) as freed */
binp->alloc[0] = NULL;
/* The reference count will be decremented to zero and the dspace
* container will be freed in sched/sched_releasetcb.c
*/
}
}
/* Mark alloc[0] (dspace) as freed */
binp->alloc[0] = NULL;
/* dspace container will be freed in sched/sched_releasetcb */
return OK;
}

View File

@ -168,7 +168,7 @@ int sched_releasetcb(FAR struct tcb_s *tcb, uint8_t ttype)
#ifdef CONFIG_PIC
/* Delete the task's allocated DSpace region (external modules only) */
if (tcb->dspace)
if (tcb->dspace != NULL)
{
if (tcb->dspace->crefs <= 1)
{