diff --git a/avahicore.cpp b/avahicore.cpp index 091514b..122bb5a 100644 --- a/avahicore.cpp +++ b/avahicore.cpp @@ -116,6 +116,7 @@ public: { QString key = name + QString::number(interface); QZeroConfPrivate *ref = static_cast(userdata); + QZeroConfService zcs; switch (event) { case AVAHI_BROWSER_FAILURE: @@ -134,11 +135,9 @@ public: if (!ref->pub->services.contains(key)) return; - QZeroConfService *zcs; zcs = ref->pub->services[key]; ref->pub->services.remove(key); emit ref->pub->serviceRemoved(zcs); - delete zcs; break; case AVAHI_BROWSER_ALL_FOR_NOW: case AVAHI_BROWSER_CACHE_EXHAUSTED: @@ -162,7 +161,7 @@ public: AVAHI_GCC_UNUSED void* userdata) { bool newRecord = 0; - QZeroConfService *zcs; + QZeroConfService zcs; QZeroConfPrivate *ref = static_cast(userdata); QString key = name + QString::number(interface); @@ -171,21 +170,20 @@ public: zcs = ref->pub->services[key]; else { newRecord = 1; - zcs = new QZeroConfService; - zcs->name = name; - zcs->type = type; - zcs->domain = domain; - zcs->host = host_name; - zcs->interfaceIndex = interface; - zcs->port = port; + zcs.setName(name); + zcs.setType(type); + zcs.setDomain(domain); + zcs.setHost(host_name); + zcs.setInterfaceIndex(interface); + zcs.setPort(port); while (txt) // get txt records { QByteArray avahiText((const char *)txt->text, txt->size); QList pair = avahiText.split('='); if (pair.size() == 2) - zcs->txt[pair.at(0)] = pair.at(1); + zcs.appendTxt(pair.at(0), pair.at(1)); else - zcs->txt[pair.at(0)] = ""; + zcs.appendTxt(pair.at(0)); txt = txt->next; } ref->pub->services.insert(key, zcs); @@ -193,10 +191,11 @@ public: char a[AVAHI_ADDRESS_STR_MAX]; avahi_address_snprint(a, sizeof(a), address); + QHostAddress addr(a); if (protocol == AVAHI_PROTO_INET6) - zcs->ipv6 = QHostAddress(a); + zcs.setIpv6(addr); else if (protocol == AVAHI_PROTO_INET) - zcs->ip = QHostAddress(a); + zcs.setIp(addr); if (newRecord) emit ref->pub->serviceAdded(zcs); @@ -207,7 +206,6 @@ public: zcs = ref->pub->services[key]; ref->pub->services.remove(key); emit ref->pub->serviceRemoved(zcs); - delete zcs; // don't delete the resolver here...we need to keep it around so Avahi will keep updating....might be able to resolve the service in the future } } @@ -219,10 +217,9 @@ public: avahi_s_service_browser_free(browser); browser = NULL; - QMap::iterator i; + QMap::iterator i; for (i = pub->services.begin(); i != pub->services.end(); i++) { - emit pub->serviceRemoved(*i); - delete *i; + emit pub->serviceRemoved(i.value()); } pub->services.clear();