[ros-diffs] [cgutman] 52201: [LWIP] - Fix a memory leak during graceful socket closure - Print a message if not all data is taken in a receive request

cgutman at svn.reactos.org cgutman at svn.reactos.org
Sun Jun 12 19:21:58 UTC 2011


Author: cgutman
Date: Sun Jun 12 19:21:56 2011
New Revision: 52201

URL: http://svn.reactos.org/svn/reactos?rev=52201&view=rev
Log:
[LWIP]
- Fix a memory leak during graceful socket closure
- Print a message if not all data is taken in a receive request

Modified:
    branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c

Modified: branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c
URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c?rev=52201&r1=52200&r2=52201&view=diff
==============================================================================
--- branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c [iso-8859-1] (original)
+++ branches/GSoC_2011/TcpIpDriver/lib/drivers/lwip/src/rostcp.c [iso-8859-1] Sun Jun 12 19:21:56 2011
@@ -85,36 +85,40 @@
         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;




More information about the Ros-diffs mailing list