[prev in list] [next in list] [prev in thread] [next in thread] 

List:       dhcp-hackers
Subject:    ISC DHCP 4.2.0-P2 failover memory leak
From:       sscdvp () gmail ! com
Date:       2011-01-12 18:58:06
Message-ID: AANLkTi=Bc6aVnv3kB+m5GxezijkEZfN9bC9zksM2arvr () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi.

It seems that at least ISC DHCP version 4.2.0-P2 has a memory leak when
being configured in failover mode and the failover partner is down.
The problem stays in omapip/connection.c when omapi_connect_list() calls for
omapi_connection_register() (while TRACING ifdef compiled in) which
allocates memory and never frees it.
When failover TCP connection is broken, DHCP tries to reconnect it every 90
secs. But because omapi_connection_object_t is referenced in
omapi_connections array, omapi_connection_destroy() is never called so every
new connection attempt creates new omapi_connection_object_t while the old
object remains. Futhermore every 10 iterations (10 reconnection attempts in
our case) omapi_connections array is extended leaking more and more memory
(see omapip/array.c omapi_array_set() routine) due to lack of support for
object dereferencing in omapip/array.c. My installation on Solaris 10
exhausts 2 MB every 24h while failover connection being inactive.

The attached patch (which solves the problem - both leaks) against 4.2.0-P2
is proposed.


Best regards,
Serghei Samsi

[Attachment #5 (text/html)]

<br><div class="gmail_quote"><div><div class="h5"><br><div \
class="gmail_quote"><div><div><div class="gmail_quote"><div><div><div \
class="gmail_quote"><div><div><div class="gmail_quote"><div><div><div \
class="gmail_quote">Hi.<br> <br>It seems that at least ISC DHCP version 4.2.0-P2 has \
a memory leak when being configured in failover mode and the failover partner is \
down.<br>



The problem stays in omapip/connection.c when omapi_connect_list() calls for \
omapi_connection_register() (while TRACING ifdef compiled in) which allocates memory \
and never frees it.<br>

When failover TCP connection is broken, DHCP tries to reconnect it every 90 secs. But \
because omapi_connection_object_t is referenced in omapi_connections array, \
omapi_connection_destroy() is never called so every new connection attempt creates \
new omapi_connection_object_t while the old object remains. Futhermore every 10 \
iterations (10 reconnection attempts in our case) omapi_connections array is extended \
leaking more and more memory (see omapip/array.c omapi_array_set() routine) due to \
lack of support for object dereferencing in omapip/array.c. My installation on \
Solaris 10 exhausts 2 MB every 24h while failover connection being inactive.<br>






<br>The attached patch (which solves the problem - both leaks) against 4.2.0-P2 is \
proposed.<br><br><br>Best regards,<br>Serghei Samsi<br><br> </div><br>
</div></div></div><br>
</div></div></div><br>
</div></div></div><br>
</div></div></div><br>
</div></div></div><br>

--000e0cd14b040a6cdd0499aac8cf--


["dhcp-4.2.0-P2-failover-twomemleaks.patch" (application/octet-stream)]

diff -ur dhcp-4.2.0-P2-orig/includes/omapip/omapip.h dhcp-4.2.0-P2-nomemleak/includes/omapip/omapip.h
--- dhcp-4.2.0-P2-orig/includes/omapip/omapip.h	2009-11-20 03:49:01.000000000 +0200
+++ dhcp-4.2.0-P2-nomemleak/includes/omapip/omapip.h	2011-01-07 13:07:44.411498000 +0200
@@ -229,6 +229,12 @@
 	return omapi_array_set (pptr, (char *)ptr, index, file, line);	      \
 }									      \
 									      \
+isc_result_t name##_array_unset (omapi_array_t *pptr, stype *ptr,	      \
+			       const char *file, int line)		      \
+{									      \
+	return omapi_array_unset (pptr, (char *)ptr, file, line);	      \
+}									      \
+									      \
 isc_result_t name##_array_lookup (stype **ptr, omapi_array_t *pptr,	      \
 				  int index, const char *file, int line)      \
 {									      \
@@ -242,6 +248,8 @@
 				  const char *, int);			      \
 isc_result_t name##_array_set (omapi_array_t *,				      \
 			       stype *, int, const char *, int);	      \
+isc_result_t name##_array_unset (omapi_array_t *,			      \
+			       stype *, const char *, int);    	     	      \
 isc_result_t name##_array_lookup (stype **,				      \
 				  omapi_array_t *, int, const char *, int)
 
@@ -615,6 +623,7 @@
 isc_result_t omapi_array_extend (omapi_array_t *, char *, int *,
 				 const char *, int);
 isc_result_t omapi_array_set (omapi_array_t *, void *, int, const char *, int);
+isc_result_t omapi_array_unset (omapi_array_t *, void *, const char *, int);
 isc_result_t omapi_array_lookup (char **,
 				 omapi_array_t *, int, const char *, int);
 OMAPI_ARRAY_TYPE_DECL(omapi_object, omapi_object_t);
diff -ur dhcp-4.2.0-P2-orig/includes/omapip/omapip_p.h dhcp-4.2.0-P2-nomemleak/includes/omapip/omapip_p.h
--- dhcp-4.2.0-P2-orig/includes/omapip/omapip_p.h	2010-02-17 22:33:55.000000000 +0200
+++ dhcp-4.2.0-P2-nomemleak/includes/omapip/omapip_p.h	2011-01-07 13:41:16.414644000 +0200
@@ -279,6 +279,8 @@
 void omapi_buffer_trace_setup (void);
 void omapi_connection_register (omapi_connection_object_t *,
 				const char *, int);
+void omapi_connection_unregister (omapi_connection_object_t *,
+				const char *, int);
 OMAPI_ARRAY_TYPE_DECL(omapi_listener, omapi_listener_object_t);
 OMAPI_ARRAY_TYPE_DECL(omapi_connection, omapi_connection_object_t);
 
diff -ur dhcp-4.2.0-P2-orig/omapip/array.c dhcp-4.2.0-P2-nomemleak/omapip/array.c
--- dhcp-4.2.0-P2-orig/omapip/array.c	2009-11-20 03:49:01.000000000 +0200
+++ dhcp-4.2.0-P2-nomemleak/omapip/array.c	2011-01-07 13:09:50.003444000 +0200
@@ -149,6 +149,50 @@
 	return ISC_R_SUCCESS;
 }
 
+isc_result_t omapi_array_unset (omapi_array_t *array, void *ptr,
+				 const char *file, int line)
+{
+	int i, k = -1, found = 0;
+	isc_result_t status = ISC_R_NOTFOUND;
+	if (!array || !ptr)
+		return ISC_R_INVALIDARG;
+	if (!array -> count || !array -> data)
+		return ISC_R_NOTFOUND;
+	for (i = 0; i < array -> count; i++) {
+		if (ptr == array -> data [i]) {
+			if (array -> deref) {
+				status = ((*array -> deref) (&array -> data [i],
+					     file, line));
+			} else {
+				array -> data [i] = 0;
+				status = ISC_R_SUCCESS;
+			}
+			k = i;
+			if (status == ISC_R_SUCCESS)
+				found = 1;
+			break;
+		}
+	}
+	if (!found || (k < 0))
+		return ISC_R_NOTFOUND;
+	for (i = k + 1; i < array -> count; i++) {
+		if (array -> data [i]) {
+			if (array -> ref) {
+				(*array -> ref) (&array -> data [k], array -> data [i], file, line);
+				if (array -> deref)
+					(*array -> deref) (&array -> data [i], file, line);
+			} else {
+				array -> data [k] = array -> data [i];
+				array -> data [i] = 0;
+			}
+			k = i;
+		}
+	}
+	if (array -> count > 0)
+		array -> count--;
+	return status;
+}
+
 isc_result_t omapi_array_lookup (char **ptr, omapi_array_t *array, int index,
 				 const char *file, int line)
 {
diff -ur dhcp-4.2.0-P2-orig/omapip/connection.c dhcp-4.2.0-P2-nomemleak/omapip/connection.c
--- dhcp-4.2.0-P2-orig/omapip/connection.c	2009-11-20 03:49:01.000000000 +0200
+++ dhcp-4.2.0-P2-nomemleak/omapip/connection.c	2011-01-07 13:13:04.640086000 +0200
@@ -300,6 +300,16 @@
 #endif
 }
 
+void omapi_connection_unregister (omapi_connection_object_t *obj,
+				const char *file, int line)
+{
+	if (!obj || !omapi_connections)
+		return;
+
+	omapi_connection_array_unset (omapi_connections, obj,
+				      file, line);
+}
+
 static void trace_connect_input (trace_type_t *ttype,
 				 unsigned length, char *buf)
 {
@@ -484,6 +494,7 @@
 		close (c -> socket);
 #if defined (TRACING)
 	}
+	omapi_connection_unregister (c, MDL);
 #endif
 	c -> state = omapi_connection_closed;
 
@@ -1040,7 +1051,8 @@
 	if (h -> type != omapi_type_connection)
 		return ISC_R_UNEXPECTED;
 	c = (omapi_connection_object_t *)(h);
-	if (c -> state == omapi_connection_connected)
+	if ((c -> state == omapi_connection_connected) ||
+	    (c -> state == omapi_connection_connecting))
 		omapi_disconnect (h, 1);
 	if (c -> listener)
 		omapi_listener_dereference (&c -> listener, file, line);


_______________________________________________
dhcp-hackers mailing list
dhcp-hackers@lists.isc.org
https://lists.isc.org/mailman/listinfo/dhcp-hackers

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic