[PATCH libinput] Fix the scan-build fake leaks

Peter Hutterer peter.hutterer at who-t.net
Wed May 9 04:32:16 UTC 2018


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 <peter.hutterer at who-t.net>
---
I don't quite know why it doesn't complain about all the other cases, but if
anyone has better ideas here, I'd appreciate it.

 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
-- 
2.14.3



More information about the wayland-devel mailing list