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 <giulio.camuffo@jollamobile.com>
This commit is contained in:
Olivier Blin 2014-12-05 14:27:06 +01:00 committed by Olivier Blin
parent babb58933f
commit 43c14e514d
2 changed files with 12 additions and 5 deletions

View File

@ -54,7 +54,10 @@ QT_BEGIN_NAMESPACE
class Q_WAYLAND_CLIENT_EXPORT QWaylandBuffer { class Q_WAYLAND_CLIENT_EXPORT QWaylandBuffer {
public: public:
QWaylandBuffer() { } QWaylandBuffer()
: mBuffer(0)
{
}
virtual ~QWaylandBuffer() { } virtual ~QWaylandBuffer() { }
wl_buffer *buffer() {return mBuffer;} wl_buffer *buffer() {return mBuffer;}
virtual QSize size() const = 0; virtual QSize size() const = 0;

View File

@ -58,7 +58,8 @@ QT_BEGIN_NAMESPACE
QWaylandShmBuffer::QWaylandShmBuffer(QWaylandDisplay *display, QWaylandShmBuffer::QWaylandShmBuffer(QWaylandDisplay *display,
const QSize &size, QImage::Format format) const QSize &size, QImage::Format format)
: mMarginsImage(0) : mShmPool(0)
, mMarginsImage(0)
{ {
int stride = size.width() * 4; int stride = size.width() * 4;
int alloc = stride * size.height(); int alloc = stride * size.height();
@ -97,9 +98,12 @@ QWaylandShmBuffer::QWaylandShmBuffer(QWaylandDisplay *display,
QWaylandShmBuffer::~QWaylandShmBuffer(void) QWaylandShmBuffer::~QWaylandShmBuffer(void)
{ {
delete mMarginsImage; delete mMarginsImage;
munmap((void *) mImage.constBits(), mImage.byteCount()); if (mImage.constBits())
wl_buffer_destroy(mBuffer); munmap((void *) mImage.constBits(), mImage.byteCount());
wl_shm_pool_destroy(mShmPool); if (mBuffer)
wl_buffer_destroy(mBuffer);
if (mShmPool)
wl_shm_pool_destroy(mShmPool);
} }
QImage *QWaylandShmBuffer::imageInsideMargins(const QMargins &margins) QImage *QWaylandShmBuffer::imageInsideMargins(const QMargins &margins)