diff --git a/share/qtcreator/qml/qmlpuppet/container/sharedmemory.h b/share/qtcreator/qml/qmlpuppet/container/sharedmemory.h
index 9e6dc794e85274f8d6f4a3c31084438abf683c51..3266fa25ed4d6fd1d67a4980ea1536bad12dd74a 100644
--- a/share/qtcreator/qml/qmlpuppet/container/sharedmemory.h
+++ b/share/qtcreator/qml/qmlpuppet/container/sharedmemory.h
@@ -61,7 +61,7 @@ public:
 protected:
 #ifdef Q_OS_UNIX
     bool initKeyInternal();
-    bool cleanHandleInternal();
+    void cleanHandleInternal();
     bool createInternal(QSharedMemory::AccessMode mode, int size);
     bool attachInternal(QSharedMemory::AccessMode mode);
     bool detachInternal();
diff --git a/share/qtcreator/qml/qmlpuppet/container/sharedmemory_unix.cpp b/share/qtcreator/qml/qmlpuppet/container/sharedmemory_unix.cpp
index 23cd47301226f5cdfe4043765e7feb2bccc4b171..53e7c7533ad16ede988f867ba755e3432245ff81 100644
--- a/share/qtcreator/qml/qmlpuppet/container/sharedmemory_unix.cpp
+++ b/share/qtcreator/qml/qmlpuppet/container/sharedmemory_unix.cpp
@@ -124,10 +124,13 @@ SharedMemory::~SharedMemory()
 {
     if (m_memory) {
         munmap(m_memory, m_size);
+        m_memory = nullptr;
+        m_size = 0;
     }
 
     if (m_fileHandle != -1) {
         close(m_fileHandle);
+        cleanHandleInternal();
         if (m_createdByMe)
             shm_unlink(m_nativeKey);
     }
@@ -142,7 +145,7 @@ void SharedMemory::setKey(const QString &key)
 
     if (isAttached())
         detach();
-    cleanHandleInternal();
+
     m_key = key;
     m_nativeKey = makePlatformSafeKey(key);
 }
@@ -299,8 +302,7 @@ void SharedMemory::setErrorString(const QString &function)
 
 bool SharedMemory::initKeyInternal()
 {
-    if (!cleanHandleInternal())
-        return false;
+    cleanHandleInternal();
 
     m_systemSemaphore.setKey(QString(), 1);
     m_systemSemaphore.setKey(m_key, 1);
@@ -341,10 +343,9 @@ int SharedMemory::handle()
     return m_fileHandle;
 }
 
-bool SharedMemory::cleanHandleInternal()
+void SharedMemory::cleanHandleInternal()
 {
     m_fileHandle = -1;
-    return true;
 }
 
 bool SharedMemory::createInternal(QSharedMemory::AccessMode mode, int size)