Skip to content

Commit 29fae07

Browse files
committed
Fix deadlock
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
1 parent 2e7840b commit 29fae07

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

mythtv/libs/libmythbase/bonjourregister.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
QMutex BonjourRegister::m_lock;
1212

1313
BonjourRegister::BonjourRegister(QObject *parent)
14-
: QObject(parent), m_dnssref(0), m_socket(NULL)
14+
: QObject(parent), m_dnssref(0), m_socket(NULL), m_haslock(false)
1515
{
1616
setenv("AVAHI_COMPAT_NOWARN", "1", 1);
1717
}
@@ -32,6 +32,11 @@ BonjourRegister::~BonjourRegister()
3232

3333
m_socket->deleteLater();
3434
m_socket = NULL;
35+
36+
if (m_haslock)
37+
{
38+
m_lock.unlock();
39+
}
3540
}
3641

3742
bool BonjourRegister::Register(uint16_t port, const QByteArray &type,
@@ -44,6 +49,7 @@ bool BonjourRegister::Register(uint16_t port, const QByteArray &type,
4449
}
4550

4651
m_lock.lock();
52+
m_haslock = true;
4753

4854
uint16_t qport = qToBigEndian(port);
4955
DNSServiceErrorType res =
@@ -70,7 +76,9 @@ bool BonjourRegister::Register(uint16_t port, const QByteArray &type,
7076
}
7177

7278
LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to register service.");
79+
m_haslock = false;
7380
m_lock.unlock();
81+
7482
return false;
7583
}
7684

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

94102
BonjourRegister *bonjour = static_cast<BonjourRegister *>(object);
103+
bonjour->m_haslock = false;
95104
bonjour->m_lock.unlock();
96105
if (kDNSServiceErr_NoError != errorcode)
97106
{

mythtv/libs/libmythbase/bonjourregister.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ class MBASE_PUBLIC BonjourRegister : public QObject
3333
DNSServiceRef m_dnssref;
3434
QSocketNotifier *m_socket;
3535
static QMutex m_lock;
36+
bool m_haslock;
3637
};
3738
#endif

0 commit comments

Comments
 (0)