From fa5d338f2af9f3636c5f15778b1dcaccb939d642 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 12 Jun 2011 19:21:56 +0000 Subject: [PATCH] [LWIP] - Fix a memory leak during graceful socket closure - Print a message if not all data is taken in a receive request svn path=/branches/GSoC_2011/TcpIpDriver/; revision=52201 --- lib/drivers/lwip/src/rostcp.c | 46 +++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/drivers/lwip/src/rostcp.c b/lib/drivers/lwip/src/rostcp.c index 38847d27c2b..f5940b0e578 100755 --- a/lib/drivers/lwip/src/rostcp.c +++ b/lib/drivers/lwip/src/rostcp.c @@ -85,37 +85,41 @@ InternalRecvEventHandler(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t e return ERR_OK; } - if (!p) - { - TCPFinEventHandler(arg, ERR_OK); - } - else + if (p) { DbgPrint("[lwIP, InternalRecvEventHandler] RECV - p:0x%x p->payload:0x%x p->len:%d p->tot_len:%d\n", p, p->payload, p->len, p->tot_len); - if (err == ERR_OK) + len = TCPRecvEventHandler(arg, p); + if (len == p->tot_len) { - len = TCPRecvEventHandler(arg, p); - if (len != 0) - { - tcp_recved(pcb, len); - - pbuf_free(p); - - return ERR_OK; - } - else - { - /* We want lwIP to store the pbuf on its queue for later */ - return ERR_TIMEOUT; - } + tcp_recved(pcb, len); + + pbuf_free(p); + + return ERR_OK; + } + else if (len != 0) + { + DbgPrint("UNTESTED CASE: NOT ALL DATA TAKEN! EXTRA DATA MAY BE LOST!\n"); + + tcp_recved(pcb, len); + + /* Possible memory leak of pbuf here? */ + + return ERR_OK; } else { - pbuf_free(p); + /* We want lwIP to store the pbuf on its queue for later */ + return ERR_TIMEOUT; } } + else if (err == ERR_OK) + { + TCPFinEventHandler(arg, ERR_OK); + tcp_close(pcb); + } return ERR_OK; }