diff main/main.cpp @ 589:09c8195c371d

Avoid exiting with locked mutex
author Chris Cannam
date Mon, 22 Jul 2013 13:24:06 +0100
parents 0b094b0fdcc4
children c06a9e8e2748 b8801b96426b
line wrap: on
line diff
--- a/main/main.cpp	Fri Jul 19 15:45:40 2013 +0100
+++ b/main/main.cpp	Mon Jul 22 13:24:06 2013 +0100
@@ -172,16 +172,21 @@
 */
 
 static QMutex cleanupMutex;
+static bool cleanedUp = false;
 
 static void
 signalHandler(int /* signal */)
 {
     // Avoid this happening more than once across threads
 
+    std::cerr << "signalHandler: cleaning up and exiting" << std::endl;
     cleanupMutex.lock();
-    std::cerr << "signalHandler: cleaning up and exiting" << std::endl;
-    TempDirectory::getInstance()->cleanup();
-    exit(0); // without releasing mutex
+    if (!cleanedUp) {
+        TempDirectory::getInstance()->cleanup();
+        cleanedUp = true;
+    }
+    cleanupMutex.unlock();
+    exit(0);
 }
 
 class SVApplication : public QApplication
@@ -422,8 +427,12 @@
 
     cleanupMutex.lock();
 
-    TransformFactory::deleteInstance();
-    TempDirectory::getInstance()->cleanup();
+    if (!cleanedUp) {
+        TransformFactory::deleteInstance();
+        TempDirectory::getInstance()->cleanup();
+        cleanedUp = true;
+    }
+
     application.releaseMainWindow();
 
 #ifdef HAVE_FFTW3F
@@ -447,6 +456,8 @@
 
     cleanupMutex.unlock();
 
+    cleanupMutex.unlock();
+
     return rv;
 }