Skip to content

Commit

Permalink
binfmt/nxflat.c: Update to last NxFLAT change: The logic must respect…
Browse files Browse the repository at this point in the history
… the reference count before freeing the dspace memory region.
  • Loading branch information
gregory-nutt committed Mar 12, 2019
1 parent ba8714d commit 622202d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 17 additions & 7 deletions binfmt/nxflat.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,27 @@ 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 */
/* Mark alloc[0] (dspace) as freed */

binp->alloc[0] = NULL;
binp->alloc[0] = NULL;

/* dspace container will be freed in sched/sched_releasetcb */
/* The reference count will be decremented to zero and the dspace
* container will be freed in sched/sched_releasetcb.c
*/
}
}

return OK;
}
Expand Down
2 changes: 1 addition & 1 deletion sched/sched/sched_releasetcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 622202d

Please sign in to comment.