From db3dcf57b1e21b0617151c4ffdf54ed41d8f534c Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 19 Feb 2026 16:30:19 +0100 Subject: [PATCH] [client,x11] fix XGetWindowProperty return handling --- client/X11/xf_cliprdr.c | 2 ++ client/X11/xf_window.c | 30 ++++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/client/X11/xf_cliprdr.c b/client/X11/xf_cliprdr.c index bca37e019..3980d88cc 100644 --- a/client/X11/xf_cliprdr.c +++ b/client/X11/xf_cliprdr.c @@ -1125,6 +1125,8 @@ static BOOL xf_cliprdr_get_requested_data(xfClipboard* clipboard, Atom target) const int rc = LogDynAndXGetWindowProperty( xfc->log, xfc->display, xfc->drawable, clipboard->property_atom, 0, 0, False, target, &type, &format_property, &length, &total_bytes, &property_data); + if (property_data) + XFree(property_data); if (rc != Success) { xf_cliprdr_send_data_response(clipboard, format, NULL, 0); diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index b1d589f0d..4b4f9a8b0 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -480,6 +480,8 @@ BOOL xf_GetWindowProperty(xfContext* xfc, Window window, Atom property, int leng Atom actual_type = None; int actual_format = 0; + WINPR_ASSERT(prop); + if (property == None) return FALSE; @@ -493,6 +495,9 @@ BOOL xf_GetWindowProperty(xfContext* xfc, Window window, Atom property, int leng if (actual_type == None) { WLog_DBG(TAG, "Property %lu does not exist", (unsigned long)property); + if (*prop) + XFree(*prop); + *prop = NULL; return FALSE; } @@ -513,16 +518,18 @@ static BOOL xf_GetNumberOfDesktops(xfContext* xfc, Window root, unsigned* pval) long* prop = (long*)bprop; *pval = 0; - if (!rc) - return FALSE; BOOL res = FALSE; - if ((*prop >= 0) && (*prop <= UINT32_MAX)) + if (rc) { - *pval = (UINT32)*prop; - res = TRUE; + if ((*prop >= 0) && (*prop <= UINT32_MAX)) + { + *pval = (UINT32)*prop; + res = TRUE; + } } - XFree(prop); + if (prop) + XFree(prop); return res; } @@ -543,12 +550,11 @@ static BOOL xf_GetCurrentDesktop(xfContext* xfc, Window root) long* prop = (long*)bprop; xfc->current_desktop = 0; - if (!rc) - return FALSE; - - xfc->current_desktop = (int)MIN(max - 1, *prop); - XFree(prop); - return TRUE; + if (rc) + xfc->current_desktop = (int)MIN(max - 1, *prop); + if (prop) + XFree(prop); + return rc; } static BOOL xf_GetWorkArea_NET_WORKAREA(xfContext* xfc, Window root)