From e79b7291ad41ee4b91c07749e228f8cccb0e3b2a Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Thu, 15 Jul 2021 21:26:54 +0200 Subject: [PATCH] i3-companion: avoid leaking X11 file descriptor --- bin/i3-companion | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/bin/i3-companion b/bin/i3-companion index 32478f8..b02b147 100755 --- a/bin/i3-companion +++ b/bin/i3-companion @@ -517,28 +517,31 @@ async def output_update(i3, event): # Grab current setup. Synchronous, but it's short enough d = display.Display() - screen = d.screen() - window = screen.root.create_window(0, 0, 1, 1, 1, screen.root_depth) - screen_resources = randr.get_screen_resources_current(window) - current_setup = set() - for output in screen_resources.outputs: - output_info = randr.get_output_info( - window, output, screen_resources.timestamp - ) - if output_info.crtc == 0: - continue - crtc_info = randr.get_crtc_info( - window, output_info.crtc, output_info.timestamp - ) - current_setup.add( - ( - output_info.name, - crtc_info.width, - crtc_info.height, - crtc_info.x, - crtc_info.y, + try: + screen = d.screen() + window = screen.root.create_window(0, 0, 1, 1, 1, screen.root_depth) + screen_resources = randr.get_screen_resources_current(window) + current_setup = set() + for output in screen_resources.outputs: + output_info = randr.get_output_info( + window, output, screen_resources.timestamp ) - ) + if output_info.crtc == 0: + continue + crtc_info = randr.get_crtc_info( + window, output_info.crtc, output_info.timestamp + ) + current_setup.add( + ( + output_info.name, + crtc_info.width, + crtc_info.height, + crtc_info.x, + crtc_info.y, + ) + ) + finally: + d.close() # Compare to current setup if current_setup == output_update.last_setup: