[lwip-users] how to free udp pcb

447 views
Skip to first unread message

Rahul Gundecha

unread,
Jan 6, 2012, 9:12:42 AM1/6/12
to Mailing list for lwIP users
Hi all,

I am writing a dns client and is using UDP sockets for the same.

I observed that UDP PCBs are not getting freed up, even after closing the sockets.
In my code,  the sockets are closed by calling lwip_close().

Call sequence here is:
lwip_close -> netconn_delete -> netconn_free

The comments on netconn_free() function says this -
 * Delete a netconn and all its resources.
 * The pcb is NOT freed (since we might not be in the right thread context do this).

If this is the case, then which is the right place to free up the udp pcb?
I tried to explicitly free up udp pcb associated with the socket by adding following code in netconn_delete(); still the problem persists.

if(conn->pcb.udp != NULL) {
udp_remove(conn->pcb.udp);
}

Thanks,
Rahul

Rahul Gundecha

unread,
Jan 6, 2012, 9:26:10 AM1/6/12
to Mailing list for lwIP users
Please note that I am using lwip version 1.4.0

Thanks,
Rahul

Kieran Mansley

unread,
Jan 7, 2012, 11:04:28 AM1/7/12
to Mailing list for lwIP users

On 6 Jan 2012, at 14:12, Rahul Gundecha wrote:

> In my code, the sockets are closed by calling lwip_close().

lwip_close() should be sufficient if you're using the sockets API. Can you give more details of what shows that the PCBs are not being freed?

Kieran
_______________________________________________
lwip-users mailing list
lwip-...@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Rahul Gundecha

unread,
Jan 9, 2012, 12:25:43 AM1/9/12
to Mailing list for lwIP users, Kieran Mansley
I am using stats_display() function (from ./src/include/lwip/stats.h) to display the stats about pcb usage. And I observe that the used udp pcb count go on increasing till the available limit and then I get errors whenever I try to create new udp pcb.

               MEM UDP_PCB
[218.174045] : avail: 8
[218.176040] : used: 8
[218.178007] : max: 8
[218.180016] : err: 2

Here I am puzzled with the comment in the code.


"Call sequence here is:
lwip_close -> netconn_delete -> netconn_free

The comments on netconn_free() function says this -
 * Delete a netconn and all its resources.
 * The pcb is NOT freed (since we might not be in the right thread context do this)."

Thanks,
Rahul

Rahul Gundecha

unread,
Jan 9, 2012, 1:28:38 AM1/9/12
to Mailing list for lwIP users, Kieran Mansley
I found the root cause, it was one socket which was not getting freed up.

Thanks,
Rahul

Simon Goldschmidt

unread,
Jan 9, 2012, 3:17:43 AM1/9/12
to Mailing list for lwIP users
Rahul Gundecha <rahul.g...@gmail.com> wrote:
> Here I am puzzled with the comment in the code.
>
> "Call sequence here is:
> lwip_close -> netconn_delete -> netconn_free
>
> The comments on netconn_free() function says this -
> * Delete a netconn and all its resources.
> * The pcb is NOT freed (since we might not be in the right thread context
> do this)."

The pcb is freed in 'do_delconn()', not in 'netconn_free()': at that point, it should already be freed.

Simon
--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone

Reply all
Reply to author
Forward
0 new messages