fix some leaks in avahi
This commit is contained in:
parent
3d93407307
commit
6dc15c611b
@ -68,8 +68,12 @@ QtAvahiService::QtAvahiService(QObject *parent) :
|
|||||||
/*! Destructs this \l{QtAvahiService}. */
|
/*! Destructs this \l{QtAvahiService}. */
|
||||||
QtAvahiService::~QtAvahiService()
|
QtAvahiService::~QtAvahiService()
|
||||||
{
|
{
|
||||||
if (d_ptr->group)
|
if (d_ptr->group) {
|
||||||
|
if (d_ptr->serviceList) {
|
||||||
|
avahi_string_list_free(d_ptr->serviceList);
|
||||||
|
}
|
||||||
avahi_entry_group_free(d_ptr->group);
|
avahi_entry_group_free(d_ptr->group);
|
||||||
|
}
|
||||||
|
|
||||||
delete d_ptr;
|
delete d_ptr;
|
||||||
}
|
}
|
||||||
@ -123,6 +127,7 @@ bool QtAvahiService::registerService(const QString &name, const quint16 &port, c
|
|||||||
// If the group is empty
|
// If the group is empty
|
||||||
if (avahi_entry_group_is_empty(d_ptr->group)) {
|
if (avahi_entry_group_is_empty(d_ptr->group)) {
|
||||||
// Add the service
|
// Add the service
|
||||||
|
d_ptr->serviceList = QtAvahiServicePrivate::createTxtList(txtRecords);
|
||||||
d_ptr->error = avahi_entry_group_add_service_strlst(d_ptr->group,
|
d_ptr->error = avahi_entry_group_add_service_strlst(d_ptr->group,
|
||||||
AVAHI_IF_UNSPEC,
|
AVAHI_IF_UNSPEC,
|
||||||
AVAHI_PROTO_UNSPEC,
|
AVAHI_PROTO_UNSPEC,
|
||||||
@ -132,7 +137,7 @@ bool QtAvahiService::registerService(const QString &name, const quint16 &port, c
|
|||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
(uint16_t)d_ptr->port,
|
(uint16_t)d_ptr->port,
|
||||||
QtAvahiServicePrivate::createTxtList(txtRecords));
|
d_ptr->serviceList);
|
||||||
|
|
||||||
// Verify if the group has to be comitted
|
// Verify if the group has to be comitted
|
||||||
if (d_ptr->error) {
|
if (d_ptr->error) {
|
||||||
@ -170,6 +175,10 @@ void QtAvahiService::resetService()
|
|||||||
if (!d_ptr->group)
|
if (!d_ptr->group)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (d_ptr->serviceList) {
|
||||||
|
avahi_string_list_free(d_ptr->serviceList);
|
||||||
|
d_ptr->serviceList = nullptr;
|
||||||
|
}
|
||||||
avahi_entry_group_reset(d_ptr->group);
|
avahi_entry_group_reset(d_ptr->group);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,6 +189,7 @@ bool QtAvahiService::updateTxtRecord(const QHash<QString, QString> &txtRecords)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Add the service
|
// Add the service
|
||||||
|
d_ptr->serviceList = QtAvahiServicePrivate::createTxtList(txtRecords);
|
||||||
d_ptr->error = avahi_entry_group_update_service_txt_strlst(d_ptr->group,
|
d_ptr->error = avahi_entry_group_update_service_txt_strlst(d_ptr->group,
|
||||||
AVAHI_IF_UNSPEC,
|
AVAHI_IF_UNSPEC,
|
||||||
AVAHI_PROTO_UNSPEC,
|
AVAHI_PROTO_UNSPEC,
|
||||||
@ -187,7 +197,7 @@ bool QtAvahiService::updateTxtRecord(const QHash<QString, QString> &txtRecords)
|
|||||||
d_ptr->name.toLatin1().data(),
|
d_ptr->name.toLatin1().data(),
|
||||||
d_ptr->type.toLatin1().data(),
|
d_ptr->type.toLatin1().data(),
|
||||||
0,
|
0,
|
||||||
QtAvahiServicePrivate::createTxtList(txtRecords));
|
d_ptr->serviceList);
|
||||||
|
|
||||||
// Verify if the group has to be comitted
|
// Verify if the group has to be comitted
|
||||||
if (d_ptr->error) {
|
if (d_ptr->error) {
|
||||||
@ -217,7 +227,9 @@ QString QtAvahiService::errorString() const
|
|||||||
|
|
||||||
bool QtAvahiService::handlCollision()
|
bool QtAvahiService::handlCollision()
|
||||||
{
|
{
|
||||||
QString alternativeServiceName = avahi_alternative_service_name(name().toStdString().data());
|
char* alt = avahi_alternative_service_name(name().toStdString().data());
|
||||||
|
QString alternativeServiceName = QLatin1String(alt);
|
||||||
|
free(alt);
|
||||||
qCDebug(dcAvahi()) << "Service name colision. Picking alternative service name" << alternativeServiceName;
|
qCDebug(dcAvahi()) << "Service name colision. Picking alternative service name" << alternativeServiceName;
|
||||||
|
|
||||||
resetService();
|
resetService();
|
||||||
|
|||||||
@ -44,6 +44,7 @@ public:
|
|||||||
|
|
||||||
QtAvahiClient *client;
|
QtAvahiClient *client;
|
||||||
AvahiEntryGroup *group;
|
AvahiEntryGroup *group;
|
||||||
|
AvahiStringList *serviceList = nullptr;
|
||||||
QString name;
|
QString name;
|
||||||
quint16 port;
|
quint16 port;
|
||||||
QString type;
|
QString type;
|
||||||
|
|||||||
Reference in New Issue
Block a user