]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: When logging I/O or timeout leak, log also raw backtrace
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 8 Aug 2017 17:07:18 +0000 (20:07 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Wed, 9 Aug 2017 12:43:11 +0000 (15:43 +0300)
This can be useful when trying to figure out where the io_loop_destroy() was
called from.

src/lib/ioloop.c

index 6e63fde510497f332867c644590f086a9403849c..977774afadf1bdd8e003e5210dffb4efa8617c0d 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "lib.h"
 #include "array.h"
+#include "backtrace-string.h"
 #include "llist.h"
 #include "time-util.h"
 #include "istream-private.h"
@@ -717,6 +718,7 @@ void io_loop_destroy(struct ioloop **_ioloop)
        struct ioloop *ioloop = *_ioloop;
        struct timeout *const *to_idx;
        struct priorityq_item *item;
+       bool leaks = FALSE;
 
        *_ioloop = NULL;
 
@@ -741,6 +743,7 @@ void io_loop_destroy(struct ioloop **_ioloop)
                else
                        i_warning("%s", error);
                io_remove(&_io);
+               leaks = TRUE;
        }
        i_assert(ioloop->io_pending_count == 0);
 
@@ -756,6 +759,7 @@ void io_loop_destroy(struct ioloop **_ioloop)
                else
                        i_warning("%s", error);
                timeout_free(to);
+               leaks = TRUE;
        }
        array_free(&ioloop->timeouts_new);
 
@@ -771,6 +775,7 @@ void io_loop_destroy(struct ioloop **_ioloop)
                else
                        i_warning("%s", error);
                timeout_free(to);
+               leaks = TRUE;
        }
        priorityq_deinit(&ioloop->timeouts);
 
@@ -786,6 +791,13 @@ void io_loop_destroy(struct ioloop **_ioloop)
                else
                        i_warning("%s", error);
                io_wait_timer_remove(&timer);
+               leaks = TRUE;
+       }
+
+       if (leaks) {
+               const char *backtrace;
+               if (backtrace_get(&backtrace) == 0)
+                       i_warning("Raw backtrace for leaks: %s", backtrace);
        }
 
        if (ioloop->handler_context != NULL)