Protect _broadcast.socket from simultaneous access.
authorCarl Hetherington <cth@carlh.net>
Mon, 11 Mar 2019 18:09:22 +0000 (18:09 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 11 Mar 2019 18:09:22 +0000 (18:09 +0000)
src/lib/encode_server.cc
src/lib/encode_server.h

index 9902c8e..d31760c 100644 (file)
@@ -97,9 +97,15 @@ EncodeServer::~EncodeServer ()
                delete i;
        }
 
-       if (_broadcast.socket) {
-               _broadcast.socket->close ();
+       {
+               boost::mutex::scoped_lock lm (_broadcast.mutex);
+               if (_broadcast.socket) {
+                       _broadcast.socket->close ();
+                       delete _broadcast.socket;
+                       _broadcast.socket = 0;
+               }
        }
+
        _broadcast.io_service.stop ();
        if (_broadcast.thread) {
                /* Ideally this would be a DCPOMATIC_ASSERT(_broadcast.thread->joinable()) but we
@@ -306,6 +312,7 @@ EncodeServer::broadcast_received ()
                }
        }
 
+       boost::mutex::scoped_lock lm (_broadcast.mutex);
        _broadcast.socket->async_receive_from (
                boost::asio::buffer (_broadcast.buffer, sizeof (_broadcast.buffer)),
                _broadcast.send_endpoint, boost::bind (&EncodeServer::broadcast_received, this)
index c9bd557..14dc773 100644 (file)
@@ -68,6 +68,7 @@ private:
                        , socket (0)
                {}
 
+               boost::mutex mutex;
                boost::thread* thread;
                boost::asio::ip::udp::socket* socket;
                char buffer[64];