优化at_socket内存泄露的修改
This commit is contained in:
parent
b9d24aff61
commit
0f6586c660
|
@ -79,7 +79,7 @@ struct at_socket *at_get_socket(int socket)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get a block to the AT socket receive list*/
|
/* get a block to the AT socket receive list*/
|
||||||
static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length)
|
static rt_err_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length)
|
||||||
{
|
{
|
||||||
at_recv_pkt_t pkt = RT_NULL;
|
at_recv_pkt_t pkt = RT_NULL;
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length)
|
||||||
if (pkt == RT_NULL)
|
if (pkt == RT_NULL)
|
||||||
{
|
{
|
||||||
LOG_E("No memory for receive packet table!");
|
LOG_E("No memory for receive packet table!");
|
||||||
return 0;
|
return -RT_ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
pkt->bfsz_totle = length;
|
pkt->bfsz_totle = length;
|
||||||
|
@ -96,7 +96,7 @@ static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length)
|
||||||
|
|
||||||
rt_slist_append(rlist, &pkt->list);
|
rt_slist_append(rlist, &pkt->list);
|
||||||
|
|
||||||
return length;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* delete and free all receive buffer list */
|
/* delete and free all receive buffer list */
|
||||||
|
@ -652,7 +652,7 @@ static void at_recv_notice_cb(struct at_socket *sock, at_socket_evt_t event, con
|
||||||
RT_ASSERT(event == AT_SOCKET_EVT_RECV);
|
RT_ASSERT(event == AT_SOCKET_EVT_RECV);
|
||||||
|
|
||||||
/* check the socket object status */
|
/* check the socket object status */
|
||||||
if (sock->magic != AT_SOCKET_MAGIC || sock->state != AT_SOCKET_CONNECT)
|
if (sock->magic != AT_SOCKET_MAGIC || sock->state == AT_SOCKET_CLOSED)
|
||||||
{
|
{
|
||||||
rt_free((void *)buff);
|
rt_free((void *)buff);
|
||||||
return;
|
return;
|
||||||
|
@ -660,7 +660,7 @@ static void at_recv_notice_cb(struct at_socket *sock, at_socket_evt_t event, con
|
||||||
|
|
||||||
/* put receive buffer to receiver packet list */
|
/* put receive buffer to receiver packet list */
|
||||||
rt_mutex_take(sock->recv_lock, RT_WAITING_FOREVER);
|
rt_mutex_take(sock->recv_lock, RT_WAITING_FOREVER);
|
||||||
if (!at_recvpkt_put(&(sock->recvpkt_list), buff, bfsz))
|
if (at_recvpkt_put(&(sock->recvpkt_list), buff, bfsz) != RT_EOK)
|
||||||
{
|
{
|
||||||
rt_free((void *)buff);
|
rt_free((void *)buff);
|
||||||
rt_mutex_release(sock->recv_lock);
|
rt_mutex_release(sock->recv_lock);
|
||||||
|
|
Loading…
Reference in New Issue