From 6e27bfff645218436da7ddf4cb303b5ce752ca7a Mon Sep 17 00:00:00 2001 From: Simon McVittie <smcv@collabora.com> Date: Mon, 31 Mar 2025 13:05:40 +0100 Subject: [PATCH] check-va-api: Clean up X11 and VA-API displays automatically Signed-off-by: Simon McVittie <smcv@collabora.com> --- helpers/check-va-api.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/helpers/check-va-api.c b/helpers/check-va-api.c index 8736059f..9a30f08c 100644 --- a/helpers/check-va-api.c +++ b/helpers/check-va-api.c @@ -39,6 +39,18 @@ #include "steam-runtime-tools/libc-utils-internal.h" +static void +clear_display (Display **displayp) +{ + clear_pointer (displayp, XCloseDisplay); +} + +static void +clear_va_display (VADisplay *displayp) +{ + clear_pointer (displayp, vaTerminate); +} + enum { OPTION_HELP = 1, @@ -414,8 +426,8 @@ main (int argc, int minor_version; unsigned int width = 1280; unsigned int height = 720; - Display *display = NULL; - VADisplay va_display = NULL; + autoclear(clear_display) Display *display = NULL; + autoclear(clear_va_display) VADisplay va_display = NULL; VASurfaceAttrib attr; VAImage img; autofree VASurfaceID *surfaces = NULL; @@ -551,11 +563,7 @@ out: vaDestroyImage (va_display, img.image_id); if (surfaces) vaDestroySurfaces (va_display, surfaces, surfaces_count); - - vaTerminate (va_display); } - if (display) - XCloseDisplay (display); return ret; } -- GitLab