解决at_socket在极限情况下内存泄漏问题

AT模块在执行AT+CLOSE并返回OK后,在实际关闭前(上报URC前)仍然有
可能接收到数据。所以接收数据时需要判断状态是否为AT_SOCKET_CONNECT。

另,at_recv_notice_cb在拒绝数据包时,没有释放数据包内存,从而导致
内在泄漏。
This commit is contained in:
wenbodong2015 2021-07-10 23:14:14 +08:00
parent e38a8e9378
commit b9d24aff61
1 changed files with 8 additions and 2 deletions

View File

@ -652,14 +652,20 @@ static void at_recv_notice_cb(struct at_socket *sock, at_socket_evt_t event, con
RT_ASSERT(event == AT_SOCKET_EVT_RECV);
/* check the socket object status */
if (sock->magic != AT_SOCKET_MAGIC)
if (sock->magic != AT_SOCKET_MAGIC || sock->state != AT_SOCKET_CONNECT)
{
rt_free((void *)buff);
return;
}
/* put receive buffer to receiver packet list */
rt_mutex_take(sock->recv_lock, RT_WAITING_FOREVER);
at_recvpkt_put(&(sock->recvpkt_list), buff, bfsz);
if (!at_recvpkt_put(&(sock->recvpkt_list), buff, bfsz))
{
rt_free((void *)buff);
rt_mutex_release(sock->recv_lock);
return;
}
rt_mutex_release(sock->recv_lock);
rt_sem_release(sock->recv_notice);