Details
-
Bug
-
Resolution: Won't Do
-
Not Evaluated
-
None
-
6.6.2
-
None
-
macOS Sonoma 14.4, Apple M2 Pro
Description
QSharedMemory does not destroy the segment in it's destructor. Docs say:
If this shared memory object is the last one connected to the shared memory segment, the detach() operation destroys the shared memory segment.
https://doc.qt.io/qt-6/qsharedmemory.html#dtor.QSharedMemory
The shared memory is created and the process exists, but when it is run again it fails to create because the destructor did not destroy the segment.
Sample program:
#include <QtDebug> #include <QCoreApplication> #include <QSharedMemory> #include <QNativeIpcKey> int main(int argc, char* argv[]) { QCoreApplication app(argc, argv); QNativeIpcKey ipcKey = QSharedMemory::platformSafeKey("org.mediafx.memory"); QSharedMemory ipcMemory(ipcKey); if (!ipcMemory.create(10, QSharedMemory::ReadWrite)) { qCritical() << "create failed:" << ipcMemory.errorString(); return 1; } qCritical() << "shmem created"; return 0; }
> ./shmem shmem created > ./shmem create failed: "QSharedMemory::attach (shm_open): already exists"
Also not that the error message is incorrect (it says "QSharedMemory::attach" but is actually from the "QSharedMemory::create" method):
https://github.com/qt/qtbase/blob/dec1863c7dc63e5788b0c6c061d36e856a6ae2b2/src/corelib/ipc/qsharedmemory_posix.cpp#L73