Skip to content

Commit

Permalink
[Linux] Fix mDNSResolver memory leak (#31709)
Browse files Browse the repository at this point in the history
* [Linux] fix memory leak

* [Python] call StopDiscovery after DiscoveryNodes

---------

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Apr 30, 2024
1 parent b15bb45 commit 1474938
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/controller/python/ChipDeviceController-Discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ PyChipError pychip_DeviceController_DiscoverCommissionableNodes(Controller::Devi
return ToPyChipError(devCtrl->DiscoverCommissionableNodes(filter));
}

PyChipError pychip_DeviceController_StopCommissionableDiscovery(Controller::DeviceCommissioner * devCtrl)
{
return ToPyChipError(devCtrl->StopCommissionableDiscovery());
}

void pychip_DeviceController_IterateDiscoveredCommissionableNodes(Controller::DeviceCommissioner * devCtrl,
IterateDiscoveredCommissionableNodesFunct cb)
{
Expand Down
7 changes: 7 additions & 0 deletions src/controller/python/chip/ChipDeviceCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,9 @@ def DiscoverCommissionableNodes(self, filterType: discovery.FilterType = discove
else:
time.sleep(timeoutSecond)

self._ChipStack.Call(
lambda: self._dmLib.pychip_DeviceController_StopCommissionableDiscovery(self.devCtrl)).raise_on_error()

return self.GetDiscoveredDevices()

def DiscoverCommissionableNodesLongDiscriminator(self, long_discriminator):
Expand Down Expand Up @@ -1567,6 +1570,10 @@ def _InitLib(self):
c_void_p, c_uint8, c_char_p]
self._dmLib.pychip_DeviceController_DiscoverCommissionableNodes.restype = PyChipError

self._dmLib.pychip_DeviceController_StopCommissionableDiscovery.argtypes = [
c_void_p]
self._dmLib.pychip_DeviceController_StopCommissionableDiscovery.restype = PyChipError

self._dmLib.pychip_DeviceController_DiscoverCommissionableNodesLongDiscriminator.argtypes = [
c_void_p, c_uint16]
self._dmLib.pychip_DeviceController_DiscoverCommissionableNodesLongDiscriminator.restype = PyChipError
Expand Down
2 changes: 1 addition & 1 deletion src/platform/Linux/DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ void MdnsAvahi::HandleResolve(AvahiServiceResolver * resolver, AvahiIfIndex inte
avahi_service_resolver_free(resolver);
context->mResolver = avahi_service_resolver_new(
context->mInstance->mClient, context->mInterface, context->mTransport, context->mName, context->mFullType.c_str(),
nullptr, context->mAddressType, static_cast<AvahiLookupFlags>(0), HandleResolve, context);
nullptr, context->mAddressType, static_cast<AvahiLookupFlags>(0), HandleResolve, userdata);
if (context->mResolver == nullptr)
{
ChipLogError(DeviceLayer, "Avahi resolve failed on retry");
Expand Down

0 comments on commit 1474938

Please sign in to comment.