Skip to content

Commit

Permalink
Fix deadlock
Browse files Browse the repository at this point in the history
If for whatever reason the BonjourRegister instance was deleted before the callback getting called ; the lock would have never been released.
The would cause the frontend failing to start following an early error to hang
  • Loading branch information
jyavenard committed Jul 9, 2013
1 parent 2e7840b commit 29fae07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion mythtv/libs/libmythbase/bonjourregister.cpp
Expand Up @@ -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);
}
Expand All @@ -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,
Expand All @@ -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 =
Expand All @@ -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;
}

Expand All @@ -92,6 +100,7 @@ void BonjourRegister::BonjourCallback(DNSServiceRef ref, DNSServiceFlags flags,
(void)flags;

BonjourRegister *bonjour = static_cast<BonjourRegister *>(object);
bonjour->m_haslock = false;
bonjour->m_lock.unlock();
if (kDNSServiceErr_NoError != errorcode)
{
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythbase/bonjourregister.h
Expand Up @@ -33,5 +33,6 @@ class MBASE_PUBLIC BonjourRegister : public QObject
DNSServiceRef m_dnssref;
QSocketNotifier *m_socket;
static QMutex m_lock;
bool m_haslock;
};
#endif

0 comments on commit 29fae07

Please sign in to comment.