From cb3cdb602a08432d8b972d06bef832e056119ad9 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 9 Jan 2016 17:18:05 +0100 Subject: [PATCH] ASAN: trigger leak before exiting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This disables the default leak-check-on-exit behavior which reports a bunch of leaks that are only leaks while exiting, at which point they don’t matter, because the operating system will clean up the memory our process used. --- i3bar/src/ipc.c | 6 ++++++ i3bar/src/xcb.c | 7 +++++++ src/commands.c | 7 +++++++ src/restore_layout.c | 7 +++++++ 4 files changed, 27 insertions(+) diff --git a/i3bar/src/ipc.c b/i3bar/src/ipc.c index 1214954d..34898663 100644 --- a/i3bar/src/ipc.c +++ b/i3bar/src/ipc.c @@ -17,6 +17,9 @@ #include #include #include +#ifdef I3_ASAN_ENABLED +#include +#endif #include "common.h" @@ -212,6 +215,9 @@ void got_data(struct ev_loop *loop, ev_io *watcher, int events) { /* EOF received. Since i3 will restart i3bar instances as appropriate, * we exit here. */ DLOG("EOF received, exiting...\n"); +#ifdef I3_ASAN_ENABLED + __lsan_do_leak_check(); +#endif clean_xcb(); exit(EXIT_SUCCESS); } diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index 590515a7..0b9f094b 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -32,6 +32,10 @@ #include #include +#ifdef I3_ASAN_ENABLED +#include +#endif + #include "common.h" #include "libi3.h" @@ -1070,6 +1074,9 @@ void xcb_chk_cb(struct ev_loop *loop, ev_check *watcher, int revents) { if (xcb_connection_has_error(xcb_connection)) { ELOG("X11 connection was closed unexpectedly - maybe your X server terminated / crashed?\n"); +#ifdef I3_ASAN_ENABLED + __lsan_do_leak_check(); +#endif exit(1); } diff --git a/src/commands.c b/src/commands.c index 515b5776..525a30fc 100644 --- a/src/commands.c +++ b/src/commands.c @@ -12,6 +12,10 @@ #include #include +#ifdef I3_ASAN_ENABLED +#include +#endif + #include "all.h" #include "shmlog.h" @@ -1658,6 +1662,9 @@ void cmd_layout_toggle(I3_CMD, const char *toggle_mode) { */ void cmd_exit(I3_CMD) { LOG("Exiting due to user command.\n"); +#ifdef I3_ASAN_ENABLED + __lsan_do_leak_check(); +#endif ipc_shutdown(); unlink(config.ipc_socket_path); xcb_disconnect(conn); diff --git a/src/restore_layout.c b/src/restore_layout.c index 4b9dc4ae..7e1b78ae 100644 --- a/src/restore_layout.c +++ b/src/restore_layout.c @@ -13,6 +13,10 @@ */ #include "all.h" +#ifdef I3_ASAN_ENABLED +#include +#endif + typedef struct placeholder_state { /** The X11 placeholder window. */ xcb_window_t window; @@ -114,6 +118,9 @@ void restore_connect(void) { if (restore_conn != NULL) { xcb_disconnect(restore_conn); } +#ifdef I3_ASAN_ENABLED + __lsan_do_leak_check(); +#endif errx(EXIT_FAILURE, "Cannot open display\n"); }