From 86442d813f7e62847ae783c96d985b0b3f0169b9 Mon Sep 17 00:00:00 2001 From: YeShanShan Date: Tue, 28 Mar 2023 16:47:12 +0800 Subject: [PATCH] fix: Crashed when get windowicon Add a check when `buf` is nullptr to avoid exit. TODO: I don't know why. --- src/modules/dock/windowinfox.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/modules/dock/windowinfox.cpp b/src/modules/dock/windowinfox.cpp index 0d95df6..cbbee80 100644 --- a/src/modules/dock/windowinfox.cpp +++ b/src/modules/dock/windowinfox.cpp @@ -367,16 +367,24 @@ QString WindowInfoX::getIconFromWindow() Atom net_wm_icon = XCB->getAtom("_NET_WM_ICON"); - unsigned char *buf; + unsigned char *buf = nullptr; int format; Atom type; unsigned long nitems, bytes; // Get image size XGetWindowProperty(dpy, xid, net_wm_icon, 0, 1, 0, AnyPropertyType, &type, &format, &nitems, &bytes, &buf); + if (!buf) { + qWarning() << "Failed to get width for window icon, window id:" << xid; + return QString(); + } int width = *(int *)buf; XFree(buf); XGetWindowProperty(dpy, xid, net_wm_icon, 1, 1, 0, AnyPropertyType, &type, &format, &nitems, &bytes, &buf); + if (!buf) { + qWarning() << "Failed to get height for window icon, window id:" << xid; + return QString(); + } int height = *(int *)buf; XFree(buf);