drm: prevent cursor buffer leakage

Use smart pointers to make sure we don't dereference valid pointers.
This commit is contained in:
Aleix Pol 2020-07-26 20:44:45 +02:00 committed by Aleix Pol Gonzalez
parent edb6159396
commit 4eda4d2b5d
2 changed files with 5 additions and 7 deletions

View file

@ -87,10 +87,8 @@ void DrmOutput::teardown()
m_crtc->setOutput(nullptr);
m_conn->setOutput(nullptr);
delete m_cursor[0];
m_cursor[0] = nullptr;
delete m_cursor[1];
m_cursor[1] = nullptr;
m_cursor[0].reset(nullptr);
m_cursor[1].reset(nullptr);
if (!m_pageFlipPending) {
deleteLater();
} //else will be deleted in the page flip handler
@ -125,7 +123,7 @@ bool DrmOutput::showCursor()
return true;
}
const bool ret = showCursor(m_cursor[m_cursorIndex]);
const bool ret = showCursor(m_cursor[m_cursorIndex].data());
if (!ret) {
return ret;
}
@ -464,7 +462,7 @@ bool DrmOutput::initCursorPlane() // TODO: Add call in init (but needs lay
bool DrmOutput::initCursor(const QSize &cursorSize)
{
auto createCursor = [this, cursorSize] (int index) {
m_cursor[index] = m_backend->createBuffer(cursorSize);
m_cursor[index].reset(m_backend->createBuffer(cursorSize));
if (!m_cursor[index]->map(QImage::Format_ARGB32_Premultiplied)) {
return false;
}

View file

@ -182,7 +182,7 @@ private:
QPoint globalPos;
bool valid = false;
} m_lastWorkingState;
DrmDumbBuffer *m_cursor[2] = {nullptr, nullptr};
QScopedPointer<DrmDumbBuffer> m_cursor[2];
int m_cursorIndex = 0;
bool m_hasNewCursor = false;
bool m_deleted = false;