sched/task/task_exithook.c: Clear atexit() function pointer before calling it. On most archs, up_assert() calls exit() so without this change, if atexit() function triggers an assertion we are in endless loop.

This commit is contained in:
Juha Niskanen
2017-11-30 06:41:57 -06:00
committed by Gregory Nutt
parent 97434ac5e5
commit e8ee632378
+24 -12
View File
@@ -98,25 +98,31 @@ static inline void task_atexit(FAR struct tcb_s *tcb)
{ {
if (group->tg_atexitfunc[index]) if (group->tg_atexitfunc[index])
{ {
/* Call the atexit function */ atexitfunc_t func;
(*group->tg_atexitfunc[index])();
/* Nullify the atexit function to prevent its reuse. */ /* Nullify the atexit function to prevent its reuse. */
func = group->tg_atexitfunc[index];
group->tg_atexitfunc[index] = NULL; group->tg_atexitfunc[index] = NULL;
/* Call the atexit function */
(*func)();
} }
} }
#else #else
if (group->tg_atexitfunc) if (group->tg_atexitfunc)
{ {
/* Call the atexit function */ atexitfunc_t func;
(*group->tg_atexitfunc)();
/* Nullify the atexit function to prevent its reuse. */ /* Nullify the atexit function to prevent its reuse. */
func = group->tg_atexitfunc;
group->tg_atexitfunc = NULL; group->tg_atexitfunc = NULL;
/* Call the atexit function */
(*func)();
} }
#endif #endif
} }
@@ -166,25 +172,31 @@ static inline void task_onexit(FAR struct tcb_s *tcb, int status)
{ {
if (group->tg_onexitfunc[index]) if (group->tg_onexitfunc[index])
{ {
/* Call the on_exit function */ onexitfunc_t func;
(*group->tg_onexitfunc[index])(status, group->tg_onexitarg[index]);
/* Nullify the on_exit function to prevent its reuse. */ /* Nullify the on_exit function to prevent its reuse. */
func = group->tg_onexitfunc[index];
group->tg_onexitfunc[index] = NULL; group->tg_onexitfunc[index] = NULL;
/* Call the on_exit function */
(*func)(status, group->tg_onexitarg[index]);
} }
} }
#else #else
if (group->tg_onexitfunc) if (group->tg_onexitfunc)
{ {
/* Call the on_exit function */ onexitfunc_t func;
(*group->tg_onexitfunc)(status, group->tg_onexitarg);
/* Nullify the on_exit function to prevent its reuse. */ /* Nullify the on_exit function to prevent its reuse. */
func = group->tg_onexitfunc;
group->tg_onexitfunc = NULL; group->tg_onexitfunc = NULL;
/* Call the on_exit function */
(*func)(status, group->tg_onexitarg);
} }
#endif #endif
} }