Attached are the diffs to the three operating system files for apr_socket_connect() within sockets.c
Good idea to make sure these work within Unix & OS2 environment; I compiled under Win32.
The patch should address the issue below.


-Norman Tuttle, developer, OpenDemand Systems, [EMAIL PROTECTED]

Norman Tuttle wrote:

While trying to memory-tune code which we are working on based on Apache Flood, an apr project, I noticed some potentially memory-leak prone code. While alloc_socket() called by apr_socket_create() does an apr_palloc() to allocate memory for a socket's remote_addr member, the apr_socket_connect() function sets the remote_addr directly to the apr_sockaddr_t * which it passes. The problem is that that defeats the purpose of allocating a buffer for it, since you're replacing with a new pointer which presumably also had to allocate its space (and the typical apr_socket_addr_get() would do that). So we need to use a memcpy() instead!

-Norman Tuttle, developer, OpenDemand Systems, [EMAIL PROTECTED]

PS Question: how many similar issues exist in the current state of the APR?


Index: apr/network_io/win32/sockets.c
===================================================================
RCS file: /home/cvspublic/apr/network_io/win32/sockets.c,v
retrieving revision 1.102
diff -u -r1.102 sockets.c
--- apr/network_io/win32/sockets.c      17 Nov 2003 19:54:08 -0000      1.102
+++ apr/network_io/win32/sockets.c      24 Nov 2003 07:50:38 -0000
@@ -386,7 +386,7 @@
         }
     }
     /* connect was OK .. amazing */
-    sock->remote_addr = sa;
+    memcpy(sock->remote_addr, sa, sizeof(apr_sockaddr_t));
     if (sock->local_addr->sa.sin.sin_port == 0) {
         sock->local_port_unknown = 1;
     }
Index: apr/network_io/unix/sockets.c
===================================================================
RCS file: /home/cvspublic/apr/network_io/unix/sockets.c,v
retrieving revision 1.116
diff -u -r1.116 sockets.c
--- apr/network_io/unix/sockets.c       24 Nov 2003 00:17:24 -0000      1.116
+++ apr/network_io/unix/sockets.c       24 Nov 2003 07:51:00 -0000
@@ -298,7 +298,7 @@
         return errno;
     }
 
-    sock->remote_addr = sa;
+    memcpy(sock->remote_addr, sa, sizeof(apr_sockaddr_t));
     if (sock->local_addr->port == 0) {
         /* connect() got us an ephemeral port */
         sock->local_port_unknown = 1;
Index: apr/network_io/os2/sockets.c
===================================================================
RCS file: /home/cvspublic/apr/network_io/os2/sockets.c,v
retrieving revision 1.67
diff -u -r1.67 sockets.c
--- apr/network_io/os2/sockets.c        17 Nov 2003 01:41:18 -0000      1.67
+++ apr/network_io/os2/sockets.c        24 Nov 2003 07:51:36 -0000
@@ -235,7 +235,7 @@
         int namelen = sizeof(sock->local_addr->sa.sin);
         getsockname(sock->socketdes, (struct sockaddr 
*)&sock->local_addr->sa.sin, 
                     &namelen);
-        sock->remote_addr = sa;
+        memcpy(sock->remote_addr, sa, sizeof(apr_sockaddr_t));
         return APR_SUCCESS;
     }
 }

Reply via email to