diff --git a/mythtv/libs/libmythbase/bonjourregister.cpp b/mythtv/libs/libmythbase/bonjourregister.cpp index 6460673341a..07ac0887931 100644 --- a/mythtv/libs/libmythbase/bonjourregister.cpp +++ b/mythtv/libs/libmythbase/bonjourregister.cpp @@ -11,7 +11,7 @@ QMutex BonjourRegister::m_lock; BonjourRegister::BonjourRegister(QObject *parent) - : QObject(parent), m_dnssref(0), m_socket(NULL) + : QObject(parent), m_dnssref(0), m_socket(NULL), m_haslock(false) { setenv("AVAHI_COMPAT_NOWARN", "1", 1); } @@ -32,6 +32,11 @@ BonjourRegister::~BonjourRegister() m_socket->deleteLater(); m_socket = NULL; + + if (m_haslock) + { + m_lock.unlock(); + } } bool BonjourRegister::Register(uint16_t port, const QByteArray &type, @@ -44,6 +49,7 @@ bool BonjourRegister::Register(uint16_t port, const QByteArray &type, } m_lock.lock(); + m_haslock = true; uint16_t qport = qToBigEndian(port); DNSServiceErrorType res = @@ -70,7 +76,9 @@ bool BonjourRegister::Register(uint16_t port, const QByteArray &type, } LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to register service."); + m_haslock = false; m_lock.unlock(); + return false; } @@ -92,6 +100,7 @@ void BonjourRegister::BonjourCallback(DNSServiceRef ref, DNSServiceFlags flags, (void)flags; BonjourRegister *bonjour = static_cast(object); + bonjour->m_haslock = false; bonjour->m_lock.unlock(); if (kDNSServiceErr_NoError != errorcode) { diff --git a/mythtv/libs/libmythbase/bonjourregister.h b/mythtv/libs/libmythbase/bonjourregister.h index c1dfa2df1ea..96f951eaba5 100644 --- a/mythtv/libs/libmythbase/bonjourregister.h +++ b/mythtv/libs/libmythbase/bonjourregister.h @@ -33,5 +33,6 @@ class MBASE_PUBLIC BonjourRegister : public QObject DNSServiceRef m_dnssref; QSocketNotifier *m_socket; static QMutex m_lock; + bool m_haslock; }; #endif