[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] questions on lwip (two TCP/IP sockets)

From: shogun
Subject: [lwip-users] questions on lwip (two TCP/IP sockets)
Date: Thu, 12 Aug 2010 14:19:02 -0400

Thanks for the help it is working much better now!  The comments about
freeing memory is from this thread:


How do you recommend I free the memory?



> static err_t socket_new_recv(void *arg, struct tcp_pcb *pcb, struct pbuf
> err_t err )
> {
>                                 ert = pbuf_free(p);
>                                 while(p->next) //see if next contains a
> NULL pointer
>                                 {
>                                                 ert = pbuf_free(p->next);
>                                                 if(ert)
>                                                 {
> error (%d) freeing data at %x\n", ert, p->next);
>                                                 }
>                                                 p = p->next;
>                                 }//end clean up memory
>                                 ert = pbuf_free(p);

You should only be calling pbuf_free once, and if the pbuf is chained,
pbuf_free will chase the chain for you, you do not need to do so.
(And if you did need to chase the chain, it's generally not a good
idea to be looking at a data structure's contents after you've freed
it, as you're doing here.)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]