From 13a0410d9b5a3fbf24ef04599c7beb68785171b6 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 11 Sep 2023 15:17:59 -0700 Subject: [PATCH] more fix --- src/mdns/mdns_mdnssd.cpp | 8 ++++++++ src/mdns/mdns_mdnssd.hpp | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/mdns/mdns_mdnssd.cpp b/src/mdns/mdns_mdnssd.cpp index 6b8bdb7e44f..fcc082faaeb 100644 --- a/src/mdns/mdns_mdnssd.cpp +++ b/src/mdns/mdns_mdnssd.cpp @@ -367,6 +367,13 @@ void PublisherMDnsSd::Process(const MainloopContext &aMainloop) if (error == kDNSServiceErr_ServiceNotRunning) { otbrLogWarning("Need to reconnect to mdnsd"); + + if (mHostsRef != nullptr) + { + DNSServiceRefDeallocate(mHostsRef); + mHostsRef = nullptr; + } + Stop(); Start(); ExitNow(); @@ -400,6 +407,7 @@ PublisherMDnsSd::DnssdHostRegistration::~DnssdHostRegistration(void) { int dnsError; + VerifyOrExit(GetPublisher().mHostsRef != nullptr); VerifyOrExit(mServiceRef != nullptr); for (const auto &recordRefAndAddress : GetRecordRefMap()) diff --git a/src/mdns/mdns_mdnssd.hpp b/src/mdns/mdns_mdnssd.hpp index 11513226c16..885b5e44440 100644 --- a/src/mdns/mdns_mdnssd.hpp +++ b/src/mdns/mdns_mdnssd.hpp @@ -156,6 +156,8 @@ class PublisherMDnsSd : public MainloopProcessor, public Publisher std::map &GetRecordRefMap() { return mRecordRefMap; } private: + PublisherMDnsSd &GetPublisher(void) { return *static_cast(mPublisher); } + DNSServiceRef mServiceRef; public: