From 610397765433d13a6d018a7d909c33a1e347e8e0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 29 Dec 2024 11:18:38 +0100 Subject: [PATCH] QWaylandShmBuffer: use make_unique / unique_ptr This keeps the QFile/QTemporaryFile objects inside a RAII wrapper at any time, which is safer. Since QScopedPointer doesn't have a similar function (and because of upcoming QT_NO_SCOPED_POINTER), also port to std::unique_ptr. Amends 32daa1a5b9ac06ae89d3aab5b4638139e72814e2. Pick-to: 6.9 6.8 Change-Id: If67a3a3bdb4fa2a06ecafd1c3dcb90e1121159b0 Reviewed-by: Thiago Macieira --- .../platforms/wayland/qwaylandshmbackingstore.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp b/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp index bdac6dc2416..b1ae2e1ae4f 100644 --- a/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp +++ b/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp @@ -16,6 +16,8 @@ #include +#include + #include #include #include @@ -59,18 +61,19 @@ QWaylandShmBuffer::QWaylandShmBuffer(QWaylandDisplay *display, fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_SEAL); #endif - QScopedPointer filePointer; + std::unique_ptr filePointer; bool opened; if (fd == -1) { - auto tmpFile = new QTemporaryFile (QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation) + + auto tmpFile = + std::make_unique(QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation) + QLatin1String("/wayland-shm-XXXXXX")); opened = tmpFile->open(); - filePointer.reset(tmpFile); + filePointer = std::move(tmpFile); } else { - auto file = new QFile; + auto file = std::make_unique(); opened = file->open(fd, QIODevice::ReadWrite | QIODevice::Unbuffered, QFile::AutoCloseHandle); - filePointer.reset(file); + filePointer = std::move(file); } // NOTE beginPaint assumes a new buffer be all zeroes, which QFile::resize does. if (!opened || !filePointer->resize(alloc)) {