rt-thread icon indicating copy to clipboard operation
rt-thread copied to clipboard

pthread_create 异常分支有内存泄漏

Open qinpan1003 opened this issue 7 years ago • 2 comments

pthread_create --> stack = (void *)rt_malloc(ptd->attr.stacksize);

此时 stack 还未赋值到 ptd->tid->stack_addr,以下两个地方失败会导致 stack 不被释放 --> ptd->tid = (rt_thread_t) rt_malloc(sizeof(struct rt_thread));
--> ptd->joinable_sem = rt_sem_create(name, 0, RT_IPC_FLAG_FIFO);

并且由于 ptd->tid->stack_addr 未赋值 _pthread_data_destroy --> rt_free(ptd->tid->stack_addr); 也是非法操作

qinpan1003 avatar Sep 30 '19 05:09 qinpan1003

pthread_create --> stack = (void *)rt_malloc(ptd->attr.stacksize);

此时 stack 还未赋值到 ptd->tid->stack_addr,以下两个地方失败会导致 stack 不被释放 --> ptd->tid = (rt_thread_t) rt_malloc(sizeof(struct rt_thread)); --> ptd->joinable_sem = rt_sem_create(name, 0, RT_IPC_FLAG_FIFO);

并且由于 ptd->tid->stack_addr 未赋值 _pthread_data_destroy --> rt_free(ptd->tid->stack_addr); 也是非法操作

看了下,pthread_create 在异常的情况下确实有内存问题

hellozimo avatar Oct 03 '19 01:10 hellozimo

fix with #3124 , thank for your contribution.

BernardXiong avatar Oct 11 '19 00:10 BernardXiong