From 43c14e514d8c7275b51e48925b6c3a48e90b38b0 Mon Sep 17 00:00:00 2001 From: Olivier Blin Date: Fri, 5 Dec 2014 14:27:06 +0100 Subject: [PATCH] Fix shm buffers init and destruction on failure Some pointers need to be initialized in QWaylandBuffer and QWaylandShmBuffer, and checked at destruction. This avoids crashes when shm surface creation fails. Change-Id: I6f6afa3cc6c67533b5130700cbc27b271764109e Reviewed-by: Giulio Camuffo --- src/plugins/platforms/wayland/qwaylandbuffer_p.h | 5 ++++- .../platforms/wayland/qwaylandshmbackingstore.cpp | 12 ++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylandbuffer_p.h b/src/plugins/platforms/wayland/qwaylandbuffer_p.h index 2bb9990f3dd..6d2bb66b392 100644 --- a/src/plugins/platforms/wayland/qwaylandbuffer_p.h +++ b/src/plugins/platforms/wayland/qwaylandbuffer_p.h @@ -54,7 +54,10 @@ QT_BEGIN_NAMESPACE class Q_WAYLAND_CLIENT_EXPORT QWaylandBuffer { public: - QWaylandBuffer() { } + QWaylandBuffer() + : mBuffer(0) + { + } virtual ~QWaylandBuffer() { } wl_buffer *buffer() {return mBuffer;} virtual QSize size() const = 0; diff --git a/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp b/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp index 6ca65f053aa..598e9f16079 100644 --- a/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp +++ b/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp @@ -58,7 +58,8 @@ QT_BEGIN_NAMESPACE QWaylandShmBuffer::QWaylandShmBuffer(QWaylandDisplay *display, const QSize &size, QImage::Format format) - : mMarginsImage(0) + : mShmPool(0) + , mMarginsImage(0) { int stride = size.width() * 4; int alloc = stride * size.height(); @@ -97,9 +98,12 @@ QWaylandShmBuffer::QWaylandShmBuffer(QWaylandDisplay *display, QWaylandShmBuffer::~QWaylandShmBuffer(void) { delete mMarginsImage; - munmap((void *) mImage.constBits(), mImage.byteCount()); - wl_buffer_destroy(mBuffer); - wl_shm_pool_destroy(mShmPool); + if (mImage.constBits()) + munmap((void *) mImage.constBits(), mImage.byteCount()); + if (mBuffer) + wl_buffer_destroy(mBuffer); + if (mShmPool) + wl_shm_pool_destroy(mShmPool); } QImage *QWaylandShmBuffer::imageInsideMargins(const QMargins &margins)