fix potentially crash-inducing race condition by removing event loops' x-thread chann...
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 17 Oct 2016 18:48:15 +0000 (14:48 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 17 Oct 2016 18:48:15 +0000 (14:48 -0400)
libs/pbd/crossthread.posix.cc
libs/pbd/crossthread.win.cc

index 5035bc49da9d60ba6da8860a234650a4d1ea9bb6..573671ba995801302441c19b1da4d3234175a921 100644 (file)
@@ -29,6 +29,14 @@ CrossThreadChannel::CrossThreadChannel (bool non_blocking)
 
 CrossThreadChannel::~CrossThreadChannel ()
 {
+       if (receive_source) {
+               /* this disconnects it from any main context it was attached in
+                  in ::attach(), this prevent its callback from being invoked
+                  after the destructor has finished.
+               */
+               g_source_destroy (receive_source);
+       }
+
        if (receive_channel) {
                 g_io_channel_unref (receive_channel);
                 receive_channel = 0;
index 5eca5fb4e8daa70ebe6c01230488bbafd2a4a136..60572bde705d75ec080f28addd5cceef8fe51bfe 100644 (file)
@@ -89,6 +89,14 @@ CrossThreadChannel::CrossThreadChannel (bool non_blocking)
 
 CrossThreadChannel::~CrossThreadChannel ()
 {
+       if (receive_source) {
+               /* this disconnects it from any main context it was attached in
+                  in ::attach(), this prevent its callback from being invoked
+                  after the destructor has finished.
+               */
+               g_source_destroy (receive_source);
+       }
+
        /* glibmm hack */
 
        if (receive_channel) {