fix: Crashed when get windowicon

Add a check when `buf` is nullptr to avoid exit.
  TODO: I don't know why.
This commit is contained in:
YeShanShan 2023-03-28 16:47:12 +08:00 committed by yeshanshan
parent 0e6489a502
commit 86442d813f

View File

@ -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);