commit 3df046122a4f8502cf6d0100ecbb91ac8af3471c
parent 0489daa5990db9d9ef88589df39f3ddef9d02191
Author: Raymond Li <hi@raymond.li>
Date: Mon, 19 Oct 2020 00:22:39 -0400
Free when layout mode is 1
TODO: 2 still throws an error
Diffstat:
| M | i3lock.c | | | 38 | ++++++++++++++++++++++++++++++-------- |
1 file changed, 30 insertions(+), 8 deletions(-)
diff --git a/i3lock.c b/i3lock.c
@@ -893,10 +893,36 @@ static void process_xkb_event(xcb_generic_event_t *gevent) {
event->state_notify.baseGroup,
event->state_notify.latchedGroup,
event->state_notify.lockedGroup);
- if (layout_text != NULL) {
- free(layout_text);
- layout_text = NULL;
- }
+ /* TODO: freeing layout_text when mode is 2 throws:
+ =================================================================
+ ==2600==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x602000000919 in thread T0
+ #0 0x7f3065b0e7cf in __interceptor_free (/lib/x86_64-linux-gnu/libasan.so.5+0x10d7cf)
+ #1 0x55c93c97e736 in process_xkb_event ../../i3lock-color/i3lock.c:898
+ #2 0x55c93c980458 in xcb_check_cb ../../i3lock-color/i3lock.c:1237
+ #3 0x7f306512bbc2 in ev_invoke_pending (/lib/x86_64-linux-gnu/libev.so.4+0x5bc2)
+ #4 0x7f306512fb92 in ev_run (/lib/x86_64-linux-gnu/libev.so.4+0x9b92)
+ #5 0x55c93c97c00c in ev_loop /usr/include/ev.h:842
+ #6 0x55c93c986762 in main ../../i3lock-color/i3lock.c:2325
+ #7 0x7f3064de70b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
+ #8 0x55c93c97920d in _start (/mnt/c/Users/raymo/Git/i3lock-color/build/i3lock+0x1520d)
+
+ 0x602000000919 is located 9 bytes inside of 13-byte region [0x602000000910,0x60200000091d)
+ allocated by thread T0 here:
+ #0 0x7f3065b0ebc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
+ #1 0x55c93c99b20f in get_atom_name ../../i3lock-color/xcb.c:531
+ #2 0x55c93c99b9c2 in xcb_get_key_group_names ../../i3lock-color/xcb.c:607
+ #3 0x55c93c97c389 in get_keylayoutname ../../i3lock-color/i3lock.c:299
+ #4 0x55c93c984e44 in main ../../i3lock-color/i3lock.c:2118
+ #5 0x7f3064de70b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
+
+ SUMMARY: AddressSanitizer: bad-free (/lib/x86_64-linux-gnu/libasan.so.5+0x10d7cf) in __interceptor_free
+ ==2600==ABORTING
+ Not freeing results in memory leak.
+ */
+ if (keylayout_mode == 1 && layout_text) {
+ free(layout_text);
+ layout_text = 0;
+ }
layout_text = get_keylayoutname(keylayout_mode, conn);
redraw_screen();
break;
@@ -2328,10 +2354,6 @@ int main(int argc, char *argv[]) {
pam_end(pam_handle, PAM_SUCCESS);
}
#endif
- if (layout_text != NULL) {
- free(layout_text);
- layout_text = NULL;
- }
if (stolen_focus == XCB_NONE) {
return 0;