This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Porting LwIP socket API with FreeRTOS

Other Parts Discussed in Thread: CC3100

Hi,

I work on TM4C 129 eval board and integrate LwIP socket API with FreeRTOS.

It can work to send/recv data with server, but I meet one memory leak problem.

In my test case:

1. create socket and connect to server.

2. exchange data with server.

3. close socket.

I repeat this test case to test the stability and meet the issue.

I print out debug log as below

-------------------------------------------------------

test run : 77
sys_mbox_new : xQueueCreate 200264f0 ++
lwip_socket(PF_INET, SOCK_STREAM, 0) = 0
lwip_connect(0, addr=10.0.2.23 port=10000)
lwip_connect(0) succeeded
lwip_send(0, data=2001f020, size=17, flags=0x0)
lwip_send(0) err=0 written=17
lwip_recvfrom(0, 20028604, 9, 0x0, ..)
lwip_recvfrom: top while sock->lastdata=0
lwip_recvfrom: netconn_recv err=0, netbuf=200193d8
lwip_recvfrom: buflen=9 len=9 off=0 sock->lastoffset=0
lwip_recvfrom(0): addr=10.0.2.23 port=10000 len=9
lwip_recvfrom: deleting netbuf=200193d8
lwip_recvfrom: buf->ref =1
pbuf_free: p->ref =1
pbuf_free: p->ref =1
pbuf_free: count =1
lwip_recvfrom(0, 20028604, 40, 0x0, ..)
lwip_recvfrom: top while sock->lastdata=0
lwip_recvfrom: netconn_recv err=0, netbuf=2001a0ec
lwip_recvfrom: buflen=40 len=40 off=0 sock->lastoffset=0
lwip_recvfrom(0): addr=10.0.2.23 port=10000 len=40
lwip_recvfrom: deleting netbuf=2001a0ec
lwip_recvfrom: buf->ref =1
pbuf_free: p->ref =1
pbuf_free: count =1
lwip_send(0, data=2001eff0, size=40, flags=0x0)
lwip_send(0) err=0 written=40
lwip_send(0, data=2001eff0, size=40, flags=0x0)
lwip_send(0) err=0 written=40
lwip_recvfrom(0, 20028604, 40, 0x0, ..)
lwip_recvfrom: top while sock->lastdata=0
lwip_recvfrom: netconn_recv err=0, netbuf=200186c4
lwip_recvfrom: buflen=40 len=40 off=0 sock->lastoffset=0
lwip_recvfrom(0): addr=10.0.2.23 port=10000 len=40
lwip_recvfrom: deleting netbuf=200186c4
lwip_recvfrom: buf->ref =1
pbuf_free: p->ref =1
pbuf_free: count =1
lwip_close (0)
lwip_close: netconn_delete
sys_mbox_free : queue free : 200264f0 --

test run : 78
sys_mbox_new : xQueueCreate 0 ++
sys_mbox_new : mbox->queue == NULL
lwip_socket(PF_INET, SOCK_STREAM, 0) = 0
lwip_connect(0, addr=10.0.2.23 port=10000)
lwip_connect(0) succeeded
lwip_send(0, data=2001f020, size=17, flags=0x0)
lwip_send(0) err=0 written=17
lwip_recvfrom(0, 20028604, 9, 0x0, ..)
lwip_recvfrom: top while sock->lastdata=0

SYS
sem.used: 2
sem.max: 2
sem.err: 0
mutex.used: 0
mutex.max: 0
mutex.err: 0
mbox.used: 2
mbox.max: 2
mbox.err: 0
Assertion "netconn_accept: invalid recvmbox" failed at line 358 in D:/work/Home_Charger/prototype_EVM/HomeCharger_OS_cc3100_lwip_129/third_party/lwip-1.4.1/src/api/api_lib.c

------------------------------------------------------

I print out the queue handle when it's created at sys_mbox_new().

In #78 run, it can't create queue handle for this transmitting. So I try to add  "QueueDelete(mbox->queue);" in sys_mbox_free(), I hope that can fix the leakage issue.

void sys_mbox_free(sys_mbox_t *mbox)
{
/* There should not be any messages waiting (if there are it is a bug). If
any are waiting, increment the mailbox error count. */
#if RTOS_FREERTOS
if(uxQueueMessagesWaiting(mbox->queue) != 0) {
#endif /* RTOS_FREERTOS */

#if SYS_STATS

STATS_INC(sys.mbox.err);
#endif /* SYS_STATS */
}

/* Clear the queue handle. */
mbox->queue = 0;

//Gavin: delete queue
vQueueDelete(mbox->queue);

/* Update the mailbox statistics. */
#if SYS_STATS
STATS_DEC(sys.mbox.used);
#endif /* SYS_STATS */

}

But I meet that system is blocked at faultISR after calling sys_mbox_free().

In generally, it should add QueueDelete() in sys_mbox_free() to avoid leakage issue, but I have no idea why it's failed at fault ISR.

Also, I have sync up the patch for tiva-tm4c129.c:

e2e.ti.com/.../374100

But it can't help my issue.

Does anyone meet the similar issue? 

thanks

Gavin