[smart] fix possible memory leak (#7832)
Signed-off-by: Shell <smokewood@qq.com>
This commit is contained in:
parent
f52095d228
commit
52d3637fba
|
@ -709,9 +709,11 @@ struct timer_obj
|
||||||
rt_uint32_t status;
|
rt_uint32_t status;
|
||||||
int sigev_signo;
|
int sigev_signo;
|
||||||
clockid_t clockid;
|
clockid_t clockid;
|
||||||
|
timer_t timer_id;
|
||||||
#ifdef RT_USING_SMART
|
#ifdef RT_USING_SMART
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
struct rt_work *work;
|
struct rt_work *work;
|
||||||
|
rt_list_t lwp_node;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -759,6 +761,17 @@ static void _lwp_timer_event_from_pid(struct rt_work *work, void *param)
|
||||||
|
|
||||||
rt_free(work);
|
rt_free(work);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int timer_list_free(rt_list_t *timer_list)
|
||||||
|
{
|
||||||
|
struct timer_obj *pos, *n;
|
||||||
|
rt_list_for_each_entry_safe(pos, n, timer_list, lwp_node)
|
||||||
|
{
|
||||||
|
timer_delete(pos->timer_id);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* RT_USING_SMART */
|
#endif /* RT_USING_SMART */
|
||||||
|
|
||||||
static void rtthread_timer_wrapper(void *timerobj)
|
static void rtthread_timer_wrapper(void *timerobj)
|
||||||
|
@ -877,6 +890,7 @@ int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid)
|
||||||
if (lwp)
|
if (lwp)
|
||||||
{
|
{
|
||||||
timer->pid = lwp_self()->pid;
|
timer->pid = lwp_self()->pid;
|
||||||
|
rt_list_insert_after(&lwp->timer, &timer->lwp_node);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -903,6 +917,8 @@ int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid)
|
||||||
return -1; /* todo:memory leak */
|
return -1; /* todo:memory leak */
|
||||||
}
|
}
|
||||||
_g_timerid[_timerid] = timer;
|
_g_timerid[_timerid] = timer;
|
||||||
|
|
||||||
|
timer->timer_id = (timer_t)(rt_ubase_t)_timerid;
|
||||||
*timerid = (timer_t)(rt_ubase_t)_timerid;
|
*timerid = (timer_t)(rt_ubase_t)_timerid;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -948,6 +964,11 @@ int timer_delete(timer_t timerid)
|
||||||
}
|
}
|
||||||
rt_ktime_hrtimer_detach(&timer->hrtimer);
|
rt_ktime_hrtimer_detach(&timer->hrtimer);
|
||||||
|
|
||||||
|
#ifdef RT_USING_SMART
|
||||||
|
if (timer->pid)
|
||||||
|
rt_list_remove(&timer->lwp_node);
|
||||||
|
#endif
|
||||||
|
|
||||||
rt_free(timer);
|
rt_free(timer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,7 @@ struct rt_lwp
|
||||||
pid_t tty_old_pgrp;
|
pid_t tty_old_pgrp;
|
||||||
pid_t session;
|
pid_t session;
|
||||||
rt_list_t t_grp;
|
rt_list_t t_grp;
|
||||||
|
rt_list_t timer; /* POSIX timer object binding to a process */
|
||||||
|
|
||||||
int leader; /*boolean value for session group_leader*/
|
int leader; /*boolean value for session group_leader*/
|
||||||
struct dfs_fdtable fdt;
|
struct dfs_fdtable fdt;
|
||||||
|
@ -165,6 +166,9 @@ void lwp_user_setting_save(rt_thread_t thread);
|
||||||
void lwp_user_setting_restore(rt_thread_t thread);
|
void lwp_user_setting_restore(rt_thread_t thread);
|
||||||
int lwp_setaffinity(pid_t pid, int cpu);
|
int lwp_setaffinity(pid_t pid, int cpu);
|
||||||
|
|
||||||
|
/* ctime lwp API */
|
||||||
|
int timer_list_free(rt_list_t *timer_list);
|
||||||
|
|
||||||
#ifdef ARCH_MM_MMU
|
#ifdef ARCH_MM_MMU
|
||||||
struct __pthread {
|
struct __pthread {
|
||||||
/* Part 1 -- these fields may be external or
|
/* Part 1 -- these fields may be external or
|
||||||
|
|
|
@ -327,6 +327,7 @@ struct rt_lwp* lwp_new(void)
|
||||||
lwp->session = -1;
|
lwp->session = -1;
|
||||||
lwp->tty = RT_NULL;
|
lwp->tty = RT_NULL;
|
||||||
rt_list_init(&lwp->t_grp);
|
rt_list_init(&lwp->t_grp);
|
||||||
|
rt_list_init(&lwp->timer);
|
||||||
lwp_user_object_lock_init(lwp);
|
lwp_user_object_lock_init(lwp);
|
||||||
lwp->address_search_head = RT_NULL;
|
lwp->address_search_head = RT_NULL;
|
||||||
rt_wqueue_init(&lwp->wait_queue);
|
rt_wqueue_init(&lwp->wait_queue);
|
||||||
|
@ -502,6 +503,7 @@ void lwp_free(struct rt_lwp* lwp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timer_list_free(&lwp->timer);
|
||||||
lwp_pid_put(lwp_to_pid(lwp));
|
lwp_pid_put(lwp_to_pid(lwp));
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
rt_free(lwp);
|
rt_free(lwp);
|
||||||
|
|
Loading…
Reference in New Issue