]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
- A memory leak when using omapi has been fixed. [ISC-Bugs #17560]
authorDavid Hankins <dhankins@isc.org>
Tue, 18 Mar 2008 18:28:14 +0000 (18:28 +0000)
committerDavid Hankins <dhankins@isc.org>
Tue, 18 Mar 2008 18:28:14 +0000 (18:28 +0000)
RELNOTES
common/lpf.c
omapip/connection.c
omapip/dispatch.c
omapip/protocol.c
server/dhcpd.c

index 39b6b8bb11d86ed4da86cd7ce90afe31710725ef..d5bc556e0309dbda2074786ef8197646f2b633de 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -75,6 +75,8 @@ work on other platforms. Please report any problems and suggested fixes to
 
 - Add DHCPv6 files in configure.
 
+- A memory leak when using omapi has been fixed.
+
                        Changes since 4.0.0 (new features)
 
 - Added DHCPv6 rapid commit support.
index 45ff5034e4b7ed77ea94428c590cd018f560e1ef..5dda6fa517f9503ce79b0c8c28782a831fed3834 100644 (file)
@@ -214,6 +214,8 @@ static void lpf_gen_filter_setup (info)
 {
        struct sock_fprog p;
 
+       memset(&p, 0, sizeof(p));
+
        /* Set up the bpf filter program structure.    This is defined in
           bpf.c */
        p.len = dhcp_bpf_filter_len;
index 93509696edf0ca92942fb7f7254af6b776170b3b..e0cb9177f12d4fc6785aa4f4203c0fe48e482110 100644 (file)
@@ -498,6 +498,28 @@ isc_result_t omapi_disconnect (omapi_object_t *h,
        /* If whatever created us registered a signal handler, send it
           a disconnect signal. */
        omapi_signal (h, "disconnect", h);
+
+       /* Disconnect from protocol object, if any. */
+       if (h->inner != NULL) {
+               if (h->inner->outer != NULL) {
+                       omapi_object_dereference(&h->inner->outer, MDL);
+               }
+               omapi_object_dereference(&h->inner, MDL);
+       }
+
+       /* XXX: the code to free buffers should be in the dereference
+               function, but there is no special-purpose function to
+               dereference connections, so these just get leaked */
+       /* Free any buffers */
+       if (c->inbufs != NULL) {
+               omapi_buffer_dereference(&c->inbufs, MDL);
+       }
+       c->in_bytes = 0;
+       if (c->outbufs != NULL) {
+               omapi_buffer_dereference(&c->outbufs, MDL);
+       }
+       c->out_bytes = 0;
+
        return ISC_R_SUCCESS;
 }
 
index b017e5bdabe5efe848e3b76dc4d117f868822a9f..dda8ce773b38a3b8d487409912716ad491e89684 100644 (file)
@@ -162,6 +162,8 @@ isc_result_t omapi_register_io_object (omapi_object_t *h,
        obj -> reader = reader;
        obj -> writer = writer;
        obj -> reaper = reaper;
+
+       omapi_io_dereference(&obj, MDL);
        return ISC_R_SUCCESS;
 }
 
@@ -273,7 +275,7 @@ isc_result_t omapi_one_dispatch (omapi_object_t *wo,
        int count;
        int desc;
        struct timeval now, to;
-       omapi_io_object_t *io, *prev;
+       omapi_io_object_t *io, *prev, *next;
        omapi_waiter_object_t *waiter;
        omapi_object_t *tmp = (omapi_object_t *)0;
 
@@ -483,44 +485,71 @@ isc_result_t omapi_one_dispatch (omapi_object_t *wo,
 
        /* Now check for I/O handles that are no longer valid,
           and remove them from the list. */
-       prev = (omapi_io_object_t *)0;
-       for (io = omapi_io_states.next; io; io = io -> next) {
-               if (io -> reaper) {
-                       if (!io -> inner ||
-                           ((*(io -> reaper)) (io -> inner) !=
-                                                       ISC_R_SUCCESS)) {
-                               omapi_io_object_t *tmp =
-                                       (omapi_io_object_t *)0;
-                               /* Save a reference to the next
-                                  pointer, if there is one. */
-                               if (io -> next)
-                                       omapi_io_reference (&tmp,
-                                                           io -> next, MDL);
-                               if (prev) {
-                                       omapi_io_dereference (&prev -> next,
-                                                             MDL);
-                                       if (tmp)
-                                               omapi_io_reference
-                                                       (&prev -> next,
-                                                        tmp, MDL);
-                               } else {
-                                       omapi_io_dereference
-                                               (&omapi_io_states.next, MDL);
-                                       if (tmp)
-                                               omapi_io_reference
-                                                   (&omapi_io_states.next,
-                                                    tmp, MDL);
-                                       else
-                                               omapi_signal_in
-                                                       ((omapi_object_t *)
-                                                        &omapi_io_states,
-                                                        "ready");
-                               }
-                               if (tmp)
-                                       omapi_io_dereference (&tmp, MDL);
+       prev = NULL;
+       io = NULL;
+       if (omapi_io_states.next != NULL) {
+               omapi_io_reference(&io, omapi_io_states.next, MDL);
+       }
+       while (io != NULL) {
+               if ((io->inner == NULL) || 
+                   ((io->reaper != NULL) && 
+                    ((io->reaper)(io->inner) != ISC_R_SUCCESS))) 
+               {
+
+                       omapi_io_object_t *tmp = NULL;
+                       /* Save a reference to the next
+                          pointer, if there is one. */
+                       if (io->next != NULL) {
+                               omapi_io_reference(&tmp, io->next, MDL);
+                               omapi_io_dereference(&io->next, MDL);
                        }
+                       if (prev != NULL) {
+                               omapi_io_dereference(&prev->next, MDL);
+                               if (tmp != NULL)
+                                       omapi_io_reference(&prev->next,
+                                                          tmp, MDL);
+                       } else {
+                               omapi_io_dereference(&omapi_io_states.next, 
+                                                    MDL);
+                               if (tmp != NULL)
+                                       omapi_io_reference
+                                           (&omapi_io_states.next,
+                                            tmp, MDL);
+                               else
+                                       omapi_signal_in(
+                                                       (omapi_object_t *)
+                                                       &omapi_io_states,
+                                                       "ready");
+                       }
+                       if (tmp != NULL)
+                               omapi_io_dereference(&tmp, MDL);
+
+               } else {
+
+                       if (prev != NULL) {
+                               omapi_io_dereference(&prev, MDL);
+                       }
+                       omapi_io_reference(&prev, io, MDL);
+
                }
-               prev = io;
+
+               /*
+                * Equivalent to:
+                *   io = io->next
+                * But using our reference counting voodoo.
+                */
+               next = NULL;
+               if (io->next != NULL) {
+                       omapi_io_reference(&next, io->next, MDL);
+               }
+               omapi_io_dereference(&io, MDL);
+               if (next != NULL) {
+                       omapi_io_reference(&io, next, MDL);
+                       omapi_io_dereference(&next, MDL);
+               }
+       }
+       if (prev != NULL) {
+               omapi_io_dereference(&prev, MDL);
        }
 
        return ISC_R_SUCCESS;
index 38966cddda36adae1880ffb008d779d9dfe67cca..a29bea995ec0278ca8d839a18b483fdf967e5d6f 100644 (file)
@@ -410,7 +410,7 @@ isc_result_t omapi_protocol_signal_handler (omapi_object_t *h,
            dmalloc_dump_outstanding ();
 #endif
 #if defined (DEBUG_RC_HISTORY_EXHAUSTIVELY)
-           dump_rc_history ();
+           dump_rc_history (h);
 #endif
            for (m = omapi_registered_messages; m; m = m -> next) {
                if (m -> protocol_object == p) {
@@ -418,6 +418,9 @@ isc_result_t omapi_protocol_signal_handler (omapi_object_t *h,
                        omapi_signal (m -> object, "disconnect");
                }
            }
+
+           /* XXX */
+           return ISC_R_SUCCESS;
        }
 
        /* Not a signal we recognize? */
@@ -492,7 +495,7 @@ isc_result_t omapi_protocol_signal_handler (omapi_object_t *h,
                        dmalloc_dump_outstanding ();
 #endif
 #if defined (DEBUG_RC_HISTORY_EXHAUSTIVELY)
-                       dump_rc_history ();
+                       dump_rc_history (h);
 #endif
 #if defined (DEBUG_MEMORY_LEAKAGE)
                }
@@ -750,7 +753,7 @@ isc_result_t omapi_protocol_signal_handler (omapi_object_t *h,
                dmalloc_dump_outstanding ();
 #endif
 #if defined (DEBUG_RC_HISTORY_EXHAUSTIVELY)
-               dump_rc_history ();
+               dump_rc_history (h);
 #endif
 #if defined (DEBUG_MEMORY_LEAKAGE)
                previous_outstanding = 0xDEADBEEF;
index 61b8f7427e3948380ec65ff8c963622e9d3e2206..ff256fe688b37caca9ba0f5d82bba2fa3025b813 100644 (file)
@@ -831,10 +831,6 @@ main(int argc, char **argv) {
        dmalloc_outstanding = 0;
 #endif
 
-#if defined (DEBUG_RC_HISTORY_EXHAUSTIVELY)
-       dump_rc_history ();
-#endif
-
        omapi_set_int_value ((omapi_object_t *)dhcp_control_object,
                             (omapi_object_t *)0, "state", server_running);