Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mdns-mdnssd] ensure allocated DnssdHostRegistration is freed #2004

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/mdns/mdns_mdnssd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,10 @@ otbrError PublisherMDnsSd::PublishHostImpl(const std::string &aName,
const std::vector<Ip6Address> &aAddresses,
ResultCallback &&aCallback)
{
otbrError ret = OTBR_ERROR_NONE;
int error = 0;
std::string fullName;
DnssdHostRegistration *registration;
otbrError ret = OTBR_ERROR_NONE;
int error = 0;
std::string fullName;
std::unique_ptr<DnssdHostRegistration> registration;

VerifyOrExit(mState == Publisher::State::kReady, ret = OTBR_ERROR_INVALID_STATE);

Expand All @@ -579,7 +579,7 @@ otbrError PublisherMDnsSd::PublishHostImpl(const std::string &aName,
otbrLogDebug("Created new DNSServiceRef for hosts: %p", mHostsRef);
}

registration = new DnssdHostRegistration(aName, aAddresses, std::move(aCallback), mHostsRef, this);
registration.reset(new DnssdHostRegistration(aName, aAddresses, std::move(aCallback), mHostsRef, this));

otbrLogInfo("Registering new host %s", aName.c_str());
for (const auto &address : aAddresses)
Expand All @@ -593,7 +593,7 @@ otbrError PublisherMDnsSd::PublishHostImpl(const std::string &aName,
registration->GetRecordRefMap()[recordRef] = address;
}

AddHostRegistration(std::unique_ptr<DnssdHostRegistration>(registration));
AddHostRegistration(std::move(registration));

exit:
if (error != kDNSServiceErr_NoError || ret != OTBR_ERROR_NONE)
Expand Down