Skip to content
Draft
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
15 changes: 14 additions & 1 deletion src/linux/init/GnsPortTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,20 @@ void GnsPortTracker::OnRefreshAllocatedPorts(const std::set<PortAllocation>& Por

for (auto it = m_allocatedPorts.begin(); it != m_allocatedPorts.end();)
{
if (Ports.find(it->first) == Ports.end())
// Ports contains the list of all Linux sockets currently active and stores the source port used by each socket
// Sockets can use a source port even though an explicit bind() was not made for that port. As long as there
// is a socket using the source port, we should not deallocate it yet.
//
// For example, a listening socket on port X and a connection socket accepted from that listening socket will both use port X.
// Even if the listening socket is closed the connection socket may still be using the same port.
//
// Port allocations are done based on protocol+port so we don't need the socket to explicitly match the address or family
// of the bind request that is tracked in m_allocatedPorts, it just needs to match the port number and protocol.
const auto matchCondition = [&](const PortAllocation& p) {
return p.Port == it->first.Port && p.Protocol == it->first.Protocol;
};

if (std::find_if(Ports.begin(), Ports.end(), matchCondition) == Ports.end())
Comment thread
FetoiuCatalin marked this conversation as resolved.
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new use of std::find_if requires <algorithm> to be included directly in this translation unit (or in a header it includes). Relying on transitive standard-library includes is non-portable and can break builds on other toolchains; add #include <algorithm> near the top of this file.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FetoiuCatalin , please add this include.

{
if (!it->second.has_value() || it->second.value() < Timestamp)
{
Expand Down
Loading