[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [plasma-workspace/Plasma/5.5] xembed-sni-proxy: Use proper deleters for libxcb structs.
From:       Michael Pyne <mpyne () kde ! org>
Date:       2015-12-26 5:32:57
Message-ID: E1aChTN-0005r4-6U () scm ! kde ! org
[Download RAW message or body]

Git commit a14a7d39c41bd3280dcc56dcd97e846e0278e812 by Michael Pyne.
Committed on 26/12/2015 at 05:30.
Pushed by mpyne into branch 'Plasma/5.5'.

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

M  +10   -6    xembed-sni-proxy/sniproxy.cpp

http://commits.kde.org/plasma-workspace/a14a7d39c41bd3280dcc56dcd97e846e0278e812

diff --git a/xembed-sni-proxy/sniproxy.cpp b/xembed-sni-proxy/sniproxy.cpp
index 847fc79..7a51767 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<xcb_get_geometry_reply_t> clientGeom(xcb_get_geometry_reply(c, \
cookie, Q_NULLPTR)); +    QScopedPointer<xcb_get_geometry_reply_t, \
QScopedPointerPodDeleter> +        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<xcb_get_geometry_reply_t> geom(xcb_get_geometry_reply(c, cookie, \
Q_NULLPTR)); +    QScopedPointer<xcb_get_geometry_reply_t, QScopedPointerPodDeleter>
+        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<xcb_get_geometry_reply_t> clientGeom(xcb_get_geometry_reply(c, \
cookieSize, Q_NULLPTR)); +    QScopedPointer<xcb_get_geometry_reply_t, \
QScopedPointerPodDeleter> +        clientGeom(xcb_get_geometry_reply(c, cookieSize, \
Q_NULLPTR));  
     auto cookie = xcb_query_pointer(c, m_windowId);
-    QScopedPointer<xcb_query_pointer_reply_t> pointer(xcb_query_pointer_reply(c, \
cookie, Q_NULLPTR)); +    QScopedPointer<xcb_query_pointer_reply_t, \
QScopedPointerPodDeleter> +        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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic