提交 40338918 编写于 作者: L lnlan

fix: 修复PR520缺陷

【背景】
https://gitee.com/openharmony/kernel_liteos_a/pulls/520
上面修改,信号处理时才会释放申请的内存,当信号被屏蔽,且一直发送该信号时,
内存占用会不断变大
【修改方案】
1.
信号发送时已经有该信号的siginfo在链表中时,不再重新申请,重复使用之前的siginfo.

【影响】
对现有的产品编译不会有影响。

re#I4DEG5
Signed-off-by: Nlanleinan <lanleinan@163.com>

Change-Id: I74b3b7ff0b9efb0179313af9a0c8d1e12d1db5bb
上级 c360a97b
......@@ -71,37 +71,44 @@ STATIC VOID OsMoveTmpInfoToUnbInfo(sig_cb *sigcb, INT32 signo)
{
SigInfoListNode *tmpInfoNode = sigcb->tmpInfoListHead;
SigInfoListNode **prevHook = &sigcb->tmpInfoListHead;
INT32 isFirstDel = 1;
while (tmpInfoNode != NULL) {
if (tmpInfoNode->info.si_signo == signo) {
/* In some case, many siginfos have same signo, only last one inserted list need copy to unbinfo. */
if (isFirstDel) {
/* copy tmpinfo to unbinfo. */
(VOID)memcpy_s(&sigcb->sigunbinfo, sizeof(siginfo_t), &tmpInfoNode->info, sizeof(siginfo_t));
isFirstDel = 0;
}
/* delete tmpinfo from tmpList. */
/* copy tmpinfo to unbinfo. */
(VOID)memcpy_s(&sigcb->sigunbinfo, sizeof(siginfo_t), &tmpInfoNode->info, sizeof(siginfo_t));
/* delete tmpinfo from tmpList. */
*prevHook = tmpInfoNode->next;
(VOID)LOS_MemFree(m_aucSysMem0, tmpInfoNode);
tmpInfoNode = *prevHook;
continue;
break;
}
prevHook = &tmpInfoNode->next;
tmpInfoNode = tmpInfoNode->next;
}
return;
}
STATIC INT32 OsAddSigInfoToTmpList(sig_cb *sigcb, siginfo_t *info)
{
SigInfoListNode *tmp = (SigInfoListNode *)LOS_MemAlloc(m_aucSysMem0, sizeof(SigInfoListNode));
/* try to find the old siginfo */
SigInfoListNode *tmp = sigcb->tmpInfoListHead;
while (tmp != NULL) {
if (tmp->info.si_signo == info->si_signo) {
/* found it, break. */
break;
}
tmp = tmp->next;
}
if (tmp == NULL) {
return LOS_NOK;
/* none, alloc new one */
tmp = (SigInfoListNode *)LOS_MemAlloc(m_aucSysMem0, sizeof(SigInfoListNode));
if (tmp == NULL) {
return LOS_NOK;
}
tmp->next = sigcb->tmpInfoListHead;
sigcb->tmpInfoListHead = tmp;
}
(VOID)memcpy_s(&tmp->info, sizeof(siginfo_t), info, sizeof(siginfo_t));
tmp->next = sigcb->tmpInfoListHead;
sigcb->tmpInfoListHead = tmp;
return LOS_OK;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册