summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2016-10-06 19:27:02 (GMT)
committerPeter Wu <peter@lekensteyn.nl>2016-10-11 21:01:17 (GMT)
commitaf7469148e15ae11c48e6e6fba7019ea8397a58b (patch)
treefda14bd654262a4f332dec257f0de5f6d0069f64
parent45751d7d8bc2a24abf75644d010018875c17daef (diff)
Fix memleak of xcb_image_t
Use xcb_image_destroy instead of free, fixes this ASAN report: Direct leak of 8294432 byte(s) in 1 object(s) allocated from: ... #5 0x7f11f9d71938 in xcb_image_get (/usr/lib/libxcb-image.so.0+0x1938) #6 0x452612 in X11ImageGrabber::getWindowPixmap(unsigned int, bool) src/PlatformBackends/X11ImageGrabber.cpp:296 #7 0x45437c in X11ImageGrabber::grabFullScreen() src/PlatformBackends/X11ImageGrabber.cpp:418 #8 0x432bdd in ImageGrabber::doImageGrab() src/PlatformBackends/ImageGrabber.cpp:90 ... REVIEW: 129137
-rw-r--r--src/PlatformBackends/X11ImageGrabber.cpp8
-rw-r--r--src/PlatformBackends/X11ImageGrabber.h7
2 files changed, 11 insertions, 4 deletions
diff --git a/src/PlatformBackends/X11ImageGrabber.cpp b/src/PlatformBackends/X11ImageGrabber.cpp
index 060b68e..371748c 100644
--- a/src/PlatformBackends/X11ImageGrabber.cpp
+++ b/src/PlatformBackends/X11ImageGrabber.cpp
@@ -217,9 +217,9 @@ QPixmap X11ImageGrabber::convertFromNative(xcb_image_t *xcbImage)
image.setColor(1, QColor(Qt::black).rgb());
}
- // done
-
- return QPixmap::fromImage(image);
+ // Image is ready. Since the backing data from xcbImage could be freed
+ // before the QPixmap goes away, a deep copy is necessary.
+ return QPixmap::fromImage(image).copy();
}
// utility functions
@@ -290,7 +290,7 @@ QPixmap X11ImageGrabber::getWindowPixmap(xcb_window_t window, bool blendPointer)
// then proceed to get an image
- CScopedPointer<xcb_image_t> xcbImage(
+ QScopedPointer<xcb_image_t, ScopedPointerXcbImageDeleter> xcbImage(
xcb_image_get(
xcbConn,
window,
diff --git a/src/PlatformBackends/X11ImageGrabber.h b/src/PlatformBackends/X11ImageGrabber.h
index dd30eac..338ffee 100644
--- a/src/PlatformBackends/X11ImageGrabber.h
+++ b/src/PlatformBackends/X11ImageGrabber.h
@@ -95,4 +95,11 @@ class X11ImageGrabber : public ImageGrabber
template <typename T> using CScopedPointer = QScopedPointer<T, QScopedPointerPodDeleter>;
+struct ScopedPointerXcbImageDeleter
+{
+ static inline void cleanup(xcb_image_t *xcbImage) {
+ xcb_image_destroy(xcbImage);
+ }
+};
+
#endif // X11IMAGEGRABBER_H