From 0500f4c9993f0000ce03dfafafe0bc7105304193 Mon Sep 17 00:00:00 2001 From: Michael Rupp Date: Wed, 2 Feb 2022 14:02:40 -0500 Subject: [PATCH] Fix github issue #14321 --- src/lib/dnssd/Discovery_ImplPlatform.cpp | 3 +++ .../OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/dnssd/Discovery_ImplPlatform.cpp b/src/lib/dnssd/Discovery_ImplPlatform.cpp index 916bf27bc..2fb1effdf 100644 --- a/src/lib/dnssd/Discovery_ImplPlatform.cpp +++ b/src/lib/dnssd/Discovery_ImplPlatform.cpp @@ -124,6 +124,9 @@ static void HandleNodeIdResolve(void * context, DnssdService * result, CHIP_ERRO #endif proxy->OnNodeIdResolved(nodeData); proxy->Release(); + + // Allocated in OnDnsResolveResult(), must be freed here + free(result); } static void HandleNodeBrowse(void * context, DnssdService * services, size_t servicesSize, CHIP_ERROR error) diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp index b47e471f8..7c555acdd 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp @@ -2317,10 +2317,13 @@ void GenericThreadStackManagerImpl_OpenThread::OnDnsResolveResult(otE error = FromOtDnsResponseToMdnsData(serviceInfo, type, dnsResult->mMdnsService, dnsResult->mServiceTxtEntry); + VerifyOrExit(error == CHIP_NO_ERROR, ); + + DeviceLayer::PlatformMgr().ScheduleWork(DispatchResolve, reinterpret_cast(dnsResult)); + exit: dnsResult->error = error; - DeviceLayer::PlatformMgr().ScheduleWork(DispatchResolve, reinterpret_cast(dnsResult)); } template