From 40add779bd13d5101d07b2319d15e96e543cd35f Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Wed, 17 Sep 2014 19:09:37 +0400 Subject: xcb: Fix memory leaks in DnD Change-Id: Ie19711c17769128db67a0b083ef72109f49bfe78 Spotted-by: Alexander Smirnov Reviewed-by: Lars Knoll --- src/plugins/platforms/xcb/qxcbdrag.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms/xcb/qxcbdrag.cpp') diff --git a/src/plugins/platforms/xcb/qxcbdrag.cpp b/src/plugins/platforms/xcb/qxcbdrag.cpp index e3fae73fd3..daea06823c 100644 --- a/src/plugins/platforms/xcb/qxcbdrag.cpp +++ b/src/plugins/platforms/xcb/qxcbdrag.cpp @@ -242,9 +242,16 @@ xcb_window_t QXcbDrag::findRealWindow(const QPoint & pos, xcb_window_t w, int md if (reply->map_state != XCB_MAP_STATE_VIEWABLE) return 0; + free(reply); + xcb_get_geometry_cookie_t gcookie = xcb_get_geometry(xcb_connection(), w); xcb_get_geometry_reply_t *greply = xcb_get_geometry_reply(xcb_connection(), gcookie, 0); - if (reply && QRect(greply->x, greply->y, greply->width, greply->height).contains(pos)) { + if (!greply) + return 0; + + QRect windowRect(greply->x, greply->y, greply->width, greply->height); + free(greply); + if (windowRect.contains(pos)) { bool windowContainsMouse = !ignoreNonXdndAwareWindows; { xcb_get_property_cookie_t cookie = @@ -255,7 +262,7 @@ xcb_window_t QXcbDrag::findRealWindow(const QPoint & pos, xcb_window_t w, int md bool isAware = reply && reply->type != XCB_NONE; free(reply); if (isAware) { - const QPoint relPos = pos - QPoint(greply->x, greply->y); + const QPoint relPos = pos - windowRect.topLeft(); // When ShapeInput and ShapeBounding are not set they return a single rectangle with the geometry of the window, this is why we // need to check both here so that in the case one is set and the other is not we still get the correct result. if (connection()->hasInputShape()) @@ -279,7 +286,7 @@ xcb_window_t QXcbDrag::findRealWindow(const QPoint & pos, xcb_window_t w, int md xcb_window_t r = 0; for (uint i = nc; !r && i--;) - r = findRealWindow(pos - QPoint(greply->x, greply->y), c[i], md-1, ignoreNonXdndAwareWindows); + r = findRealWindow(pos - windowRect.topLeft(), c[i], md-1, ignoreNonXdndAwareWindows); free(reply); if (r) -- cgit v1.2.3