kernel - Fix memory leak on iocom terminaion
authorMatthew Dillon <dillon@apollo.backplane.com>
Fri, 1 Feb 2013 17:54:43 +0000 (09:54 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Fri, 1 Feb 2013 17:54:43 +0000 (09:54 -0800)
* freerd_state was being cleaned up by the reader thread, but during
  decomissioning the writer thread can simulate incoming packets
  to cleanly shutdown open transactions, and this can reload
  freerd_state.

* Move the cleanup for freerd_state and freewr_state out of the
  reader/writer threads and into kdmsg_iocom_uninit() proper.

* Fixes dangling 112 bytes of memory left allocated after uninit.

sys/kern/kern_dmsg.c

index 706f211..017576a 100644 (file)
@@ -249,6 +249,8 @@ kdmsg_lnk_span_reply(kdmsg_state_t *state, kdmsg_msg_t *msg)
 void
 kdmsg_iocom_uninit(kdmsg_iocom_t *iocom)
 {
+       kdmsg_state_t *state;
+
        /*
         * Ask the cluster controller to go away
         */
@@ -261,6 +263,19 @@ kdmsg_iocom_uninit(kdmsg_iocom_t *iocom)
        }
 
        /*
+        * Cleanup caches
+        */
+       if ((state = iocom->freerd_state) != NULL) {
+               iocom->freerd_state = NULL;
+               kdmsg_state_free(state);
+       }
+
+       if ((state = iocom->freewr_state) != NULL) {
+               iocom->freewr_state = NULL;
+               kdmsg_state_free(state);
+       }
+
+       /*
         * Drop communications descriptor
         */
        if (iocom->msg_fp) {
@@ -282,7 +297,6 @@ kdmsg_iocom_thread_rd(void *arg)
        kdmsg_iocom_t *iocom = arg;
        dmsg_hdr_t hdr;
        kdmsg_msg_t *msg = NULL;
-       kdmsg_state_t *state;
        size_t hbytes;
        size_t abytes;
        int error = 0;
@@ -353,11 +367,6 @@ kdmsg_iocom_thread_rd(void *arg)
        if (msg)
                kdmsg_msg_free(msg);
 
-       if ((state = iocom->freerd_state) != NULL) {
-               iocom->freerd_state = NULL;
-               kdmsg_state_free(state);
-       }
-
        /*
         * Shutdown the socket before waiting for the transmit side.
         *
@@ -553,11 +562,6 @@ cleanupwr:
        }
        iocom->flags |= KDMSG_IOCOMF_EXITNOACC;
 
-       if ((state = iocom->freewr_state) != NULL) {
-               iocom->freewr_state = NULL;
-               kdmsg_state_free(state);
-       }
-
        lockmgr(&iocom->msglk, LK_RELEASE);
 
        /*