after debug for long time, i think the

memp_malloc: out of memory in pool TCP_PCB

is not caused by memory leak, because i found the TCP_PCB will be used in
future connection.

My test is simple,

Only one socket active, and make connection, receive back 20K data. Another
thread will close the socket after some time. In this test, I could see the
out of memory problem is gone after add netbuf_delet(buf) .  I could see out
of memoy for TCP_PCB.

Is it possible it is normal result, because the socket close won't delete
the TCP structure form PCB now, just make a flag. The connection TCP will be
delete after some kinds of time out.

I am sure
1> there is a kind of memoy leak in my test case. Close a blocked socket.
     It is fixed by add check whether conn avaiable after netbuf_delet(buf)
in lwip_recvfrom.

2> I am not sure about the out of TCP_PCB is memory leak.


2008/12/26 Muhamad Ikhwan Ismail <[email protected]>

>
>
> Hi..
>
> TCP_PCB are resource under MEMP module (in 1.3.0) and can only be released
> by closing the connection (socket/netconn API/raw API). Hope this helps.
>
> Greetings,
> M Ikhwan Ismail
>
> ------------------------------
> Date: Fri, 26 Dec 2008 17:04:11 +0800
> From: [email protected]
> To: [email protected]
> Subject: Re: [lwip-users] socket memory problem
>
>
>     if(sock->conn == NULL)
>     {
>           /**
>            *  Need free memory
>            */
>           !!! I have not find how to free the memory. I tried
> netbuf_delete(buf); but not solve problem
>     }
>
> The netbuf_delet(buf) will free the some of the memory, but I meet out of
> TCP_PCB
>
> memp_malloc: out of memory in pool TCP_PCB
>
> i could not find where to free TCP_PCB in my case.
>
> Give me a suggstion.
>
> On Fri, Dec 26, 2008 at 2:52 PM, yueyue papa <[email protected]> wrote:
>
> we find the memory leak in current usage today.
>
> block in
> struct netbuf *
> netconn_recv(struct netconn *conn)
> {
>    ....
>     msg.msg.conn = conn;
>     if (buf != NULL) {
>       msg.msg.msg.r.len = buf->p->tot_len;
>     } else {
>       msg.msg.msg.r.len = 1;
>     }
>     TCPIP_APIMSG(&msg);  <=== block here
>
> If net receive block TCPIP_APIMSG, the close will wake up the the block,
> and the memory leak will happen in socket.c
>
> int
> lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
>         struct sockaddr *from, socklen_t *fromlen)
> {
>
>      ...
>       /* No data was left from the previous operation, so we try to get
>       some from the network. */
>       sock->lastdata = buf = netconn_recv(sock->conn);
>       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom: netconn_recv
> netbuf=%p\n", (void*)buf));  <===get return
>
>     /**
>      * socket connection validate check
>      */
>     if(sock->conn == NULL)
>     {
>           /**
>            *  Need free memory
>            */
>           !!! I have not find how to free the memory. I tried
> netbuf_delete(buf); but not solve problem
>     }
>
> There is no socket connection valid check in here, the invalid socet will
> cuase memory leak.
>
> Any suggestion is welcome
>
>
>
>
> On Wed, Dec 24, 2008 at 1:16 PM, yueyue papa <[email protected]> wrote:
>
> Thanks all
>
> The problem is solved
>
> One task call lwip_read
>
> block in
> struct netbuf *
> netconn_recv(struct netconn *conn)
> {
> ...
> #endif /* LWIP_TCP */
>   } else {
> #if (LWIP_UDP || LWIP_RAW)
> #if LWIP_SO_RCVTIMEO
>     if (sys_arch_mbox_fetch(conn->recvmbox, (void *)&buf,
> conn->recv_timeout)==SYS_ARCH_TIMEOUT) {  <====block here
>       buf = NULL;
>     }
> #else
>     sys_arch_mbox_fetch(conn->recvmbox, (void *)&buf, 0);
> #endif /* LWIP_SO_RCVTIMEO*/
>
> ...
> }
>
> Another task called
> lwip_close() won't let the netconn_recv exit the block status.
>
> And then our application make force delete task, so one memory is leaked.
>
> As Alain M suggest, we added a timeout for lwip_read, so the block will be
> exit, and then the block thread won't be killed later.
>
> If lwip_close could wake up the lwip_read is perfect.
>
>
>
> On Wed, Dec 24, 2008 at 12:30 AM, Alain M. <[email protected]> wrote:
>
>
> yueyue papa escreveu:
>
> I am using lwIP socket interface. I meet a kind of memory leak.
>
> My question
> 1. Whether my flow break the lwIP pre-required  condition.
>
> Already answered by Kieran
>
> 2. How could I make quick fixed.
>
> As this problems will happen in almost all platforms, including Linux
> usualy, what I use to do is: make your socket read non blocking with a
> "small" timeout, on exit make a loop testing for an abort flag and if
> requested, cleanup and exit the thread, that is a "normal" way of aborting.
>
> Alain
>
>
>
>
> _______________________________________________
> lwip-users mailing list
> [email protected]
> http://lists.nongnu.org/mailman/listinfo/lwip-users
>
>
>
>
>
>  ------------------------------
> It's the same Hotmail�. If by "same" you mean up to 70% faster. Get your
> account 
> now.<http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_broad1_122008>
>
> _______________________________________________
> lwip-users mailing list
> [email protected]
> http://lists.nongnu.org/mailman/listinfo/lwip-users
>
_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to