From b3e9144c3a326af26d94e0cbd448357d3072a650 Mon Sep 17 00:00:00 2001
From: Elena Zaretskaya <sweetiebrier@yandex.ru>
Date: Sat, 9 Apr 2016 00:46:24 +0400
Subject: [PATCH] Fix FPE under EGLFS_KMS if mesa-10.2.7

If mesa-10.2.7 is installed, gbm_bo_create returns NULL
(QEglFSKmsCursor ctor, qeglfskmscursor.cpp:80), but after
that the pointer m_bo is used in function QEGlFSKmsCursor::changeCursor
without verification.

Task-number: QTBUG-52404
Change-Id: I5b1b15d751e46a5200248e7a8642f7917dedd220
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
---
 .../deviceintegration/eglfs_kms/qeglfskmscursor.cpp      | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmscursor.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmscursor.cpp
index dda61e3901d..97ea3f1eca0 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmscursor.cpp
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmscursor.cpp
@@ -100,8 +100,10 @@ QEglFSKmsCursor::~QEglFSKmsCursor()
         drmModeMoveCursor(kmsScreen->device()->fd(), kmsScreen->output().crtc_id, 0, 0);
     }
 
-    gbm_bo_destroy(m_bo);
-    m_bo = Q_NULLPTR;
+    if (m_bo) {
+        gbm_bo_destroy(m_bo);
+        m_bo = Q_NULLPTR;
+    }
 }
 
 void QEglFSKmsCursor::pointerEvent(const QMouseEvent &event)
@@ -114,6 +116,9 @@ void QEglFSKmsCursor::changeCursor(QCursor *windowCursor, QWindow *window)
 {
     Q_UNUSED(window);
 
+    if (!m_bo)
+        return;
+
     if (!m_visible)
         return;
 
-- 
GitLab