From c162ac6d7be4877b43d59b36022d1807fe812ea7 Mon Sep 17 00:00:00 2001 From: Andy Salisbury Date: Thu, 18 Nov 2021 14:29:23 -0500 Subject: [PATCH 1/2] Compile fixes. Disable adding the MDNS context to the list. Not sure what the correct solution is. --- src/platform/Darwin/DnssdImpl.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/platform/Darwin/DnssdImpl.cpp b/src/platform/Darwin/DnssdImpl.cpp index c654747d6b5b00..da3812d3846c75 100644 --- a/src/platform/Darwin/DnssdImpl.cpp +++ b/src/platform/Darwin/DnssdImpl.cpp @@ -461,6 +461,8 @@ static CHIP_ERROR GetAddrInfo(void * context, DnssdResolveCallback callback, uin else { // -1 is the local only interface. In this case, we can use localhost ::1 + /* + // This fails to compile because sdRef is uninitialised. Initialising it to nullptr causes Add to fail. CHIP_ERROR chip_err = MdnsContexts::GetInstance().Add(sdCtx, sdRef); if (chip_err != CHIP_NO_ERROR) { @@ -468,6 +470,7 @@ static CHIP_ERROR GetAddrInfo(void * context, DnssdResolveCallback callback, uin CheckForSuccess(sdCtx, __func__, kDNSServiceErr_Unknown, true); return chip_err; } + */ sockaddr_in6 sockaddr; memset(&sockaddr, 0, sizeof(sockaddr)); @@ -477,9 +480,9 @@ static CHIP_ERROR GetAddrInfo(void * context, DnssdResolveCallback callback, uin sockaddr.sin6_port = htons((unsigned short) port); uint32_t ttl = 120; // default TTL for records with hostnames is 120 seconds uint32_t interface = 0; // Set interface to ANY (0) - network stack can decide how to route this. - OnGetAddrInfo(sdRef, 0 /* flags */, 0, kDNSServiceErr_NoError, hostname, reinterpret_cast(&sockaddr), ttl, - sdCtx); - return err; + OnGetAddrInfo(sdRef, 0 /* flags */, interface, kDNSServiceErr_NoError, hostname, reinterpret_cast(&sockaddr), + ttl, sdCtx); + return CHIP_NO_ERROR; } } From 8a690601cc5620af7eafd57eb6fe8309be1eb617 Mon Sep 17 00:00:00 2001 From: Andy Salisbury Date: Thu, 18 Nov 2021 14:48:26 -0500 Subject: [PATCH 2/2] Remove the MDNS context handling, and free the text entries. --- src/platform/Darwin/DnssdImpl.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/platform/Darwin/DnssdImpl.cpp b/src/platform/Darwin/DnssdImpl.cpp index da3812d3846c75..d9481e88f915d3 100644 --- a/src/platform/Darwin/DnssdImpl.cpp +++ b/src/platform/Darwin/DnssdImpl.cpp @@ -460,18 +460,6 @@ static CHIP_ERROR GetAddrInfo(void * context, DnssdResolveCallback callback, uin } else { - // -1 is the local only interface. In this case, we can use localhost ::1 - /* - // This fails to compile because sdRef is uninitialised. Initialising it to nullptr causes Add to fail. - CHIP_ERROR chip_err = MdnsContexts::GetInstance().Add(sdCtx, sdRef); - if (chip_err != CHIP_NO_ERROR) - { - // TODO: Above doesn't check the error return, but it does seem like we want to trigger the callback if this fails. - CheckForSuccess(sdCtx, __func__, kDNSServiceErr_Unknown, true); - return chip_err; - } - */ - sockaddr_in6 sockaddr; memset(&sockaddr, 0, sizeof(sockaddr)); sockaddr.sin6_len = sizeof(sockaddr); @@ -480,8 +468,17 @@ static CHIP_ERROR GetAddrInfo(void * context, DnssdResolveCallback callback, uin sockaddr.sin6_port = htons((unsigned short) port); uint32_t ttl = 120; // default TTL for records with hostnames is 120 seconds uint32_t interface = 0; // Set interface to ANY (0) - network stack can decide how to route this. - OnGetAddrInfo(sdRef, 0 /* flags */, interface, kDNSServiceErr_NoError, hostname, reinterpret_cast(&sockaddr), + OnGetAddrInfo(nullptr, 0 /* flags */, interface, kDNSServiceErr_NoError, hostname, reinterpret_cast(&sockaddr), ttl, sdCtx); + + // Don't leak memory. + std::vector::iterator textEntry; + for (textEntry = sdCtx->textEntries.begin(); textEntry != sdCtx->textEntries.end(); textEntry++) + { + free(const_cast(textEntry->mKey)); + free(const_cast(textEntry->mData)); + } + return CHIP_NO_ERROR; } }