From a14a7d39c41bd3280dcc56dcd97e846e0278e812 Mon Sep 17 00:00:00 2001 From: Michael Pyne Date: Thu, 24 Dec 2015 23:43:48 -0500 Subject: [PATCH] Use proper deleters for libxcb structs. Coverity noted we were mismatching new Foo with free(foo), which is undefined behavior (CID 1340556). While I was fixing that I noticed we have the same issue with QScopedPointer<>: when using QSP to track objects returned by libxcb, we must use free() to release memory, not C++ delete. (e.g. see http://xcb.freedesktop.org/manual/group__XCB____API.html#ga6727f2bfb24769655e52d1f1c50f58fe) QScopedPointer will do this if we use QScopedPointerPodDeleter. REVIEW:126512 --- xembed-sni-proxy/sniproxy.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/xembed-sni-proxy/sniproxy.cpp b/xembed-sni-proxy/sniproxy.cpp index 847fc795a..7a51767d0 100644 --- a/xembed-sni-proxy/sniproxy.cpp +++ b/xembed-sni-proxy/sniproxy.cpp @@ -88,7 +88,8 @@ SNIProxy::SNIProxy(xcb_window_t wid, QObject* parent): auto c = QX11Info::connection(); auto cookie = xcb_get_geometry(c, m_windowId); - QScopedPointer clientGeom(xcb_get_geometry_reply(c, cookie, Q_NULLPTR)); + QScopedPointer + clientGeom(xcb_get_geometry_reply(c, cookie, Q_NULLPTR)); //create a container window auto screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data; @@ -242,7 +243,8 @@ QImage SNIProxy::getImageNonComposite() const { auto c = QX11Info::connection(); auto cookie = xcb_get_geometry(c, m_windowId); - QScopedPointer geom(xcb_get_geometry_reply(c, cookie, Q_NULLPTR)); + QScopedPointer + geom(xcb_get_geometry_reply(c, cookie, Q_NULLPTR)); xcb_image_t *image = xcb_image_get(c, m_windowId, 0, 0, geom->width, geom->height, 0xFFFFFF, XCB_IMAGE_FORMAT_Z_PIXMAP); @@ -405,10 +407,12 @@ void SNIProxy::sendClick(uint8_t mouseButton, int x, int y) auto c = QX11Info::connection(); auto cookieSize = xcb_get_geometry(c, m_windowId); - QScopedPointer clientGeom(xcb_get_geometry_reply(c, cookieSize, Q_NULLPTR)); + QScopedPointer + clientGeom(xcb_get_geometry_reply(c, cookieSize, Q_NULLPTR)); auto cookie = xcb_query_pointer(c, m_windowId); - QScopedPointer pointer(xcb_query_pointer_reply(c, cookie, Q_NULLPTR)); + QScopedPointer + pointer(xcb_query_pointer_reply(c, cookie, Q_NULLPTR)); /*qCDebug(SNIPROXY) << "samescreen" << pointer->same_screen << endl << "root x*y" << pointer->root_x << pointer->root_y << endl << "win x*y" << pointer->win_x << pointer->win_y;*/ @@ -453,7 +457,7 @@ void SNIProxy::sendClick(uint8_t mouseButton, int x, int y) event->detail = mouseButton; xcb_send_event(c, false, m_windowId, XCB_EVENT_MASK_BUTTON_PRESS, (char *) event); - free(event); + delete event; } //mouse up @@ -474,7 +478,7 @@ void SNIProxy::sendClick(uint8_t mouseButton, int x, int y) event->detail = mouseButton; xcb_send_event(c, false, m_windowId, XCB_EVENT_MASK_BUTTON_RELEASE, (char *) event); - free(event); + delete event; } #ifndef VISUAL_DEBUG