i3 / i3

A tiling window manager for X11
https://i3wm.org/
BSD 3-Clause "New" or "Revised" License
9.44k stars 777 forks source link

get the build address sanitizer-clean #4087

Open stapelberg opened 4 years ago

stapelberg commented 4 years ago

While working on issue #4086, I noticed that we currently seem to have a bunch of unaddressed address sanitizer warnings, and at least some of these are legit memory leaks.

I’ll send a few changes to make asan easier to work with first, then try to clean up the issues it finds.

orestisfl commented 4 years ago

Can you share the logs?

stapelberg commented 4 years ago

When building with -O2, a few places similar to https://github.com/i3/i3/pull/4088 are reported.

Aside from that, I’m getting reports about libxcb:

=================================================================
==3628304==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 1024 byte(s) in 32 object(s) allocated from:
    #0 0x7f0566c79b3a in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f05669f0b17  (/usr/lib/libxcb.so.1+0xeb17)

SUMMARY: AddressSanitizer: 1024 byte(s) leaked in 32 allocation(s).

In general, the following files are flagged:

The following test logfiles contain AddressSanitizer or LeakSanitizer reports:
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-113-urgent.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-165-for_window.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-166-assign.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-167-workspace_layout.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-170-force_focus_wrapping.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-174-border-config.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-176-workspace-baf.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-183-config-variables.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-189-floating-constraints.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-194-regress-floating-size.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-203-regress-assign-and-move.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-212-assign-urgency.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-217-NET_CURRENT_DESKTOP.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-228-border-widths.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-229-cleanup-tmpdir.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-240-focus-on-window-activation.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-242-no-focus.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-245-move-position-mouse.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-247-config-line-continuation.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-266-net-moveresize-window.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-268-ipc-config.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-287-edge-borders.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-290-keypress-numlock.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-291-swap.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-308-focus_wrapping.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-506-focus-right.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-525-i3bar-mouse-bindings.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-529-net-wm-desktop.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-532-xresources.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-533-randr15.t
    testsuite-2020-05-17-15-52-40-4.18-282-gca6d6821/i3-log-for-538-i3bar-primary-output.t
stapelberg commented 4 years ago

After suppressing libxcb.so like so:

# testcases/lib/TestWorker.pm
@@ -125,6 +125,8 @@ sub worker_wait {
                    $options->{coverage},
                    $options->{restart});

+            $ENV{LSAN_OPTIONS} = "suppressions=lsan.supp";
+
             package main;
             local $@;
             do $file;

…and placing lsan.supp next to the relevant binary (e.g. build/i3):

echo leak:libxcb.so > ~/i3/build/lsan.supp

I get:

The following test logfiles contain AddressSanitizer or LeakSanitizer reports:
    testsuite-2020-05-17-16-06-37-4.18-282-g05557d8d/i3-log-for-165-for_window.t
    testsuite-2020-05-17-16-06-37-4.18-282-g05557d8d/i3-log-for-268-ipc-config.t
    testsuite-2020-05-17-16-06-37-4.18-282-g05557d8d/i3-log-for-308-focus_wrapping.t
    testsuite-2020-05-17-16-06-37-4.18-282-g05557d8d/i3-log-for-525-i3bar-mouse-bindings.t
    testsuite-2020-05-17-16-06-37-4.18-282-g05557d8d/i3-log-for-529-net-wm-desktop.t
    testsuite-2020-05-17-16-06-37-4.18-282-g05557d8d/i3-log-for-533-randr15.t
    testsuite-2020-05-17-16-06-37-4.18-282-g05557d8d/i3-log-for-538-i3bar-primary-output.t
stapelberg commented 4 years ago

Here are all the leak logs:

~/i3/build meson % grep -A 100 Sanitizer latest/i3-log-for-* | perl -E 'for (<>) { print if /ERROR: LeakSanitizer/ ... /SUMMARY/ }' | xclip
latest/i3-log-for-165-for_window.t:==3634393==ERROR: LeakSanitizer: detected memory leaks
latest/i3-log-for-165-for_window.t-
latest/i3-log-for-165-for_window.t-Direct leak of 14 byte(s) in 2 object(s) allocated from:
latest/i3-log-for-165-for_window.t-    #0 0x7fdb0972fb3a in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
latest/i3-log-for-165-for_window.t-    #1 0x7fdb084ed187 in __vasprintf_internal (/usr/lib/libc.so.6+0x7e187)
latest/i3-log-for-165-for_window.t-
latest/i3-log-for-165-for_window.t------------------------------------------------------
latest/i3-log-for-165-for_window.t-Suppressions used:
latest/i3-log-for-165-for_window.t-  count      bytes template
latest/i3-log-for-165-for_window.t-     54       1812 libxcb.so
latest/i3-log-for-165-for_window.t------------------------------------------------------
latest/i3-log-for-165-for_window.t-
latest/i3-log-for-165-for_window.t:SUMMARY: AddressSanitizer: 14 byte(s) leaked in 2 allocation(s).
latest/i3-log-for-268-ipc-config.t:==3635045==ERROR: LeakSanitizer: detected memory leaks
latest/i3-log-for-268-ipc-config.t-
latest/i3-log-for-268-ipc-config.t-Direct leak of 32 byte(s) in 1 object(s) allocated from:
latest/i3-log-for-268-ipc-config.t-    #0 0x7fb8085dbb3a in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
latest/i3-log-for-268-ipc-config.t-    #1 0x55e7b37a4409 in smalloc ../libi3/safewrappers.c:22
latest/i3-log-for-268-ipc-config.t-    #2 0x55e7b377f822 in start_nagbar ../src/util.c:401
latest/i3-log-for-268-ipc-config.t-    #3 0x55e7b371ac41 in start_config_error_nagbar ../src/config_parser.c:813
latest/i3-log-for-268-ipc-config.t-    #4 0x55e7b371cd97 in parse_file ../src/config_parser.c:1112
latest/i3-log-for-268-ipc-config.t-    #5 0x55e7b370dd17 in load_configuration ../src/config.c:228
latest/i3-log-for-268-ipc-config.t-    #6 0x55e7b374db1f in main ../src/main.c:617
latest/i3-log-for-268-ipc-config.t-    #7 0x7fb807342022 in __libc_start_main (/usr/lib/libc.so.6+0x27022)
latest/i3-log-for-268-ipc-config.t-
latest/i3-log-for-268-ipc-config.t:SUMMARY: AddressSanitizer: 32 byte(s) leaked in 1 allocation(s).
latest/i3-log-for-308-focus_wrapping.t:==3634373==ERROR: LeakSanitizer: detected memory leaks
latest/i3-log-for-308-focus_wrapping.t-
latest/i3-log-for-308-focus_wrapping.t-Direct leak of 1415 byte(s) in 125 object(s) allocated from:
latest/i3-log-for-308-focus_wrapping.t-    #0 0x7fec066ddb3a in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
latest/i3-log-for-308-focus_wrapping.t-    #1 0x7fec0549b187 in __vasprintf_internal (/usr/lib/libc.so.6+0x7e187)
latest/i3-log-for-308-focus_wrapping.t-
latest/i3-log-for-308-focus_wrapping.t------------------------------------------------------
latest/i3-log-for-308-focus_wrapping.t-Suppressions used:
latest/i3-log-for-308-focus_wrapping.t-  count      bytes template
latest/i3-log-for-308-focus_wrapping.t-     98       3136 libxcb.so
latest/i3-log-for-308-focus_wrapping.t------------------------------------------------------
latest/i3-log-for-308-focus_wrapping.t-
latest/i3-log-for-308-focus_wrapping.t:SUMMARY: AddressSanitizer: 1415 byte(s) leaked in 125 allocation(s).
latest/i3-log-for-308-focus_wrapping.t:==3634756==ERROR: LeakSanitizer: detected memory leaks
latest/i3-log-for-308-focus_wrapping.t-
latest/i3-log-for-308-focus_wrapping.t-Direct leak of 1246 byte(s) in 112 object(s) allocated from:
latest/i3-log-for-308-focus_wrapping.t-    #0 0x7f703c3adb3a in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
latest/i3-log-for-308-focus_wrapping.t-    #1 0x7f703b16b187 in __vasprintf_internal (/usr/lib/libc.so.6+0x7e187)
latest/i3-log-for-308-focus_wrapping.t-
latest/i3-log-for-308-focus_wrapping.t------------------------------------------------------
latest/i3-log-for-308-focus_wrapping.t-Suppressions used:
latest/i3-log-for-308-focus_wrapping.t-  count      bytes template
latest/i3-log-for-308-focus_wrapping.t-    105       3360 libxcb.so
latest/i3-log-for-308-focus_wrapping.t------------------------------------------------------
latest/i3-log-for-308-focus_wrapping.t-
latest/i3-log-for-308-focus_wrapping.t:SUMMARY: AddressSanitizer: 1246 byte(s) leaked in 112 allocation(s).
latest/i3-log-for-308-focus_wrapping.t:==3635276==ERROR: LeakSanitizer: detected memory leaks
latest/i3-log-for-308-focus_wrapping.t-
latest/i3-log-for-308-focus_wrapping.t-Direct leak of 2655 byte(s) in 225 object(s) allocated from:
latest/i3-log-for-308-focus_wrapping.t-    #0 0x7f16d8fdfb3a in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
latest/i3-log-for-308-focus_wrapping.t-    #1 0x7f16d7d9d187 in __vasprintf_internal (/usr/lib/libc.so.6+0x7e187)
latest/i3-log-for-308-focus_wrapping.t-
latest/i3-log-for-308-focus_wrapping.t------------------------------------------------------
latest/i3-log-for-308-focus_wrapping.t-Suppressions used:
latest/i3-log-for-308-focus_wrapping.t-  count      bytes template
latest/i3-log-for-308-focus_wrapping.t-    133       4256 libxcb.so
latest/i3-log-for-308-focus_wrapping.t------------------------------------------------------
latest/i3-log-for-308-focus_wrapping.t-
latest/i3-log-for-308-focus_wrapping.t:SUMMARY: AddressSanitizer: 2655 byte(s) leaked in 225 allocation(s).
latest/i3-log-for-308-focus_wrapping.t:==3635362==ERROR: LeakSanitizer: detected memory leaks
latest/i3-log-for-308-focus_wrapping.t-
latest/i3-log-for-308-focus_wrapping.t-Direct leak of 2655 byte(s) in 225 object(s) allocated from:
latest/i3-log-for-308-focus_wrapping.t-    #0 0x7f82bddf6b3a in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
latest/i3-log-for-308-focus_wrapping.t-    #1 0x7f82bcbb4187 in __vasprintf_internal (/usr/lib/libc.so.6+0x7e187)
latest/i3-log-for-308-focus_wrapping.t-
latest/i3-log-for-308-focus_wrapping.t------------------------------------------------------
latest/i3-log-for-308-focus_wrapping.t-Suppressions used:
latest/i3-log-for-308-focus_wrapping.t-  count      bytes template
latest/i3-log-for-308-focus_wrapping.t-    133       4256 libxcb.so
latest/i3-log-for-308-focus_wrapping.t------------------------------------------------------
latest/i3-log-for-308-focus_wrapping.t-
latest/i3-log-for-308-focus_wrapping.t:SUMMARY: AddressSanitizer: 2655 byte(s) leaked in 225 allocation(s).
latest/i3-log-for-525-i3bar-mouse-bindings.t:==3635025==ERROR: LeakSanitizer: detected memory leaks
latest/i3-log-for-525-i3bar-mouse-bindings.t-
latest/i3-log-for-525-i3bar-mouse-bindings.t-Direct leak of 13 byte(s) in 1 object(s) allocated from:
latest/i3-log-for-525-i3bar-mouse-bindings.t-    #0 0x7ff3b07dfb3a in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
latest/i3-log-for-525-i3bar-mouse-bindings.t-    #1 0x7ff3afa9a187 in __vasprintf_internal (/usr/lib/libc.so.6+0x7e187)
latest/i3-log-for-525-i3bar-mouse-bindings.t-
latest/i3-log-for-525-i3bar-mouse-bindings.t:SUMMARY: AddressSanitizer: 13 byte(s) leaked in 1 allocation(s).
latest/i3-log-for-529-net-wm-desktop.t:==3634776==ERROR: LeakSanitizer: detected memory leaks
latest/i3-log-for-529-net-wm-desktop.t-
latest/i3-log-for-529-net-wm-desktop.t-Direct leak of 13 byte(s) in 1 object(s) allocated from:
latest/i3-log-for-529-net-wm-desktop.t-    #0 0x7f8c9d7ffb3a in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
latest/i3-log-for-529-net-wm-desktop.t-    #1 0x7f8c9caba187 in __vasprintf_internal (/usr/lib/libc.so.6+0x7e187)
latest/i3-log-for-529-net-wm-desktop.t-
latest/i3-log-for-529-net-wm-desktop.t:SUMMARY: AddressSanitizer: 13 byte(s) leaked in 1 allocation(s).
latest/i3-log-for-533-randr15.t:==3635341==ERROR: LeakSanitizer: detected memory leaks
latest/i3-log-for-533-randr15.t-
latest/i3-log-for-533-randr15.t-Direct leak of 13 byte(s) in 1 object(s) allocated from:
latest/i3-log-for-533-randr15.t-2020-05-17 16:06:40 - ../src/handlers.c:handle_event:1271 - event type 14, xkb_base 85
latest/i3-log-for-533-randr15.t-    #0 0x7fba786ecb3a in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
latest/i3-log-for-533-randr15.t-    #1 0x7fba779a7187 in __vasprintf_internal (/usr/lib/libc.so.6+0x7e187)
latest/i3-log-for-533-randr15.t-
latest/i3-log-for-533-randr15.t-2020-05-17 16:06:40 - ../src/ipc.c:ipc_new_client_on_fd:1503 - IPC: new client connected on fd 10
latest/i3-log-for-533-randr15.t:SUMMARY: AddressSanitizer: 13 byte(s) leaked in 1 allocation(s).
latest/i3-log-for-533-randr15.t:==3635339==ERROR: LeakSanitizer: detected memory leaks
latest/i3-log-for-533-randr15.t-
latest/i3-log-for-533-randr15.t-Direct leak of 15 byte(s) in 1 object(s) allocated from:
latest/i3-log-for-533-randr15.t-    #0 0x7f87b5e48b3a in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
latest/i3-log-for-533-randr15.t-    #1 0x7f87b4c06187 in __vasprintf_internal (/usr/lib/libc.so.6+0x7e187)
latest/i3-log-for-533-randr15.t-
latest/i3-log-for-533-randr15.t------------------------------------------------------
latest/i3-log-for-533-randr15.t-Suppressions used:
latest/i3-log-for-533-randr15.t-  count      bytes template
latest/i3-log-for-533-randr15.t-      1         32 libxcb.so
latest/i3-log-for-533-randr15.t------------------------------------------------------
latest/i3-log-for-533-randr15.t-
latest/i3-log-for-533-randr15.t:SUMMARY: AddressSanitizer: 15 byte(s) leaked in 1 allocation(s).
latest/i3-log-for-533-randr15.t:==3635353==ERROR: LeakSanitizer: detected memory leaks
latest/i3-log-for-533-randr15.t-
latest/i3-log-for-533-randr15.t-Direct leak of 560 byte(s) in 7 object(s) allocated from:
latest/i3-log-for-533-randr15.t-    #0 0x7f4960152b3a in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
latest/i3-log-for-533-randr15.t-    #1 0x56223b8a935c in smalloc ../libi3/safewrappers.c:22
latest/i3-log-for-533-randr15.t-    #2 0x56223b89110f in workspaces_start_map_cb ../i3bar/src/workspaces.c:184
latest/i3-log-for-533-randr15.t-    #3 0x7f495f897726  (/usr/lib/libyajl.so.2+0x3726)
latest/i3-log-for-533-randr15.t-
latest/i3-log-for-533-randr15.t-Indirect leak of 280 byte(s) in 7 object(s) allocated from:
latest/i3-log-for-533-randr15.t-    #0 0x7f4960152d48 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:153
latest/i3-log-for-533-randr15.t-    #1 0x56223b8a93b2 in scalloc ../libi3/safewrappers.c:29
latest/i3-log-for-533-randr15.t-    #2 0x56223b8a9a34 in i3string_from_utf8_with_length ../libi3/string.c:55
latest/i3-log-for-533-randr15.t-    #3 0x56223b8a9ae8 in i3string_from_markup_with_length ../libi3/string.c:72
latest/i3-log-for-533-randr15.t-    #4 0x56223b890982 in workspaces_string_cb ../i3bar/src/workspaces.c:136
latest/i3-log-for-533-randr15.t-    #5 0x7f495f897870  (/usr/lib/libyajl.so.2+0x3870)
latest/i3-log-for-533-randr15.t-
latest/i3-log-for-533-randr15.t-Indirect leak of 14 byte(s) in 7 object(s) allocated from:
latest/i3-log-for-533-randr15.t-    #0 0x7f4960152fa0 in __interceptor_realloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:163
latest/i3-log-for-533-randr15.t-    #1 0x56223b8a940f in srealloc ../libi3/safewrappers.c:36
latest/i3-log-for-533-randr15.t-    #2 0x56223b8aa6d0 in convert_utf8_to_ucs2 ../libi3/ucs2_conversion.c:100
latest/i3-log-for-533-randr15.t-    #3 0x56223b8a9efa in i3string_ensure_ucs2 ../libi3/string.c:133
latest/i3-log-for-533-randr15.t-    #4 0x56223b8aa104 in i3string_get_num_glyphs ../libi3/string.c:193
latest/i3-log-for-533-randr15.t-    #5 0x56223b8a7bb4 in predict_text_width ../libi3/font.c:503
latest/i3-log-for-533-randr15.t-    #6 0x56223b890a14 in workspaces_string_cb ../i3bar/src/workspaces.c:141
latest/i3-log-for-533-randr15.t-    #7 0x7f495f897870  (/usr/lib/libyajl.so.2+0x3870)
latest/i3-log-for-533-randr15.t-
latest/i3-log-for-533-randr15.t-Indirect leak of 14 byte(s) in 7 object(s) allocated from:
latest/i3-log-for-533-randr15.t-    #0 0x7f4960152b3a in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
latest/i3-log-for-533-randr15.t-    #1 0x7f495f5eece9 in g_malloc (/usr/lib/libglib-2.0.so.0+0x65ce9)
latest/i3-log-for-533-randr15.t-
latest/i3-log-for-533-randr15.t-Indirect leak of 14 byte(s) in 7 object(s) allocated from:
latest/i3-log-for-533-randr15.t-    #0 0x7f4960152b3a in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
latest/i3-log-for-533-randr15.t-    #1 0x7f49600b8dc5 in __interceptor_strndup /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:379
latest/i3-log-for-533-randr15.t-    #2 0x56223b8a94b0 in sstrndup ../libi3/safewrappers.c:50
latest/i3-log-for-533-randr15.t-    #3 0x56223b8905f2 in workspaces_string_cb ../i3bar/src/workspaces.c:111
latest/i3-log-for-533-randr15.t-    #4 0x7f495f897870  (/usr/lib/libyajl.so.2+0x3870)
latest/i3-log-for-533-randr15.t-
latest/i3-log-for-533-randr15.t:SUMMARY: AddressSanitizer: 882 byte(s) leaked in 35 allocation(s).
latest/i3-log-for-538-i3bar-primary-output.t:==3634899==ERROR: LeakSanitizer: detected memory leaks
latest/i3-log-for-538-i3bar-primary-output.t-
latest/i3-log-for-538-i3bar-primary-output.t-Direct leak of 13 byte(s) in 1 object(s) allocated from:
latest/i3-log-for-538-i3bar-primary-output.t-    #0 0x7f6d889b4b3a in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:144
latest/i3-log-for-538-i3bar-primary-output.t-    #1 0x7f6d87c6f187 in __vasprintf_internal (/usr/lib/libc.so.6+0x7e187)
latest/i3-log-for-538-i3bar-primary-output.t-
latest/i3-log-for-538-i3bar-primary-output.t:SUMMARY: AddressSanitizer: 13 byte(s) leaked in 1 allocation(s).