Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-123730

QSharedMemory does not destroy the segment in destructor

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • Not Evaluated
    • None
    • 6.6.2
    • Core: Other
    • None
    • macOS Sonoma 14.4, Apple M2 Pro
    • macOS

    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

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            rectalogic Andrew Wason
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes