From f206903823f56bef989bbc50b5b7539797f3fb87 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 9 May 2018 14:29:52 +1000 Subject: [PATCH] Fix the scan-build fake leaks We pass the event to libinput_post_event() where it is appended to the event queue. Except in these three cases clang doesn't seem to realize what's happening and complains about memory leaks. I tried workarounds like g_steal_pointer() but nothing I tried helps. So let's just pretend we're freeing it when clang looks at us. Signed-off-by: Peter Hutterer --- src/libinput.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libinput.c b/src/libinput.c index 7b329afe..1309ca18 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -2129,6 +2129,12 @@ notify_added_device(struct libinput_device *device) post_base_event(device, LIBINPUT_EVENT_DEVICE_ADDED, &added_device_event->base); + +#ifdef __clang_analyzer__ + /* clang doesn't realize we're not leaking the event here, so + * pretend to free it */ + free(added_device_event); +#endif } void @@ -2141,6 +2147,12 @@ notify_removed_device(struct libinput_device *device) post_base_event(device, LIBINPUT_EVENT_DEVICE_REMOVED, &removed_device_event->base); + +#ifdef __clang_analyzer__ + /* clang doesn't realize we're not leaking the event here, so + * pretend to free it */ + free(removed_device_event); +#endif } static inline bool @@ -2728,6 +2740,12 @@ switch_notify_toggle(struct libinput_device *device, post_device_event(device, time, LIBINPUT_EVENT_SWITCH_TOGGLE, &switch_event->base); + +#ifdef __clang_analyzer__ + /* clang doesn't realize we're not leaking the event here, so + * pretend to free it */ + free(switch_event); +#endif } static void