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

fix(libsinsp): memleak in sinsp_dns_manager #1526

Merged
merged 1 commit into from
Nov 30, 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
19 changes: 12 additions & 7 deletions userspace/libsinsp/dns_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class sinsp_dns_manager

void cleanup();

static sinsp_dns_manager& get()
{
static sinsp_dns_manager instance;
return instance;
};
static sinsp_dns_manager& get()
{
static sinsp_dns_manager instance;
return instance;
};

void set_erase_timeout(uint64_t ns)
{
Expand Down Expand Up @@ -83,8 +83,13 @@ class sinsp_dns_manager
m_base_refresh_timeout(10 * ONE_SECOND_IN_NS),
m_max_refresh_timeout(320 * ONE_SECOND_IN_NS)
{};
sinsp_dns_manager(sinsp_dns_manager const&) = delete;
void operator=(sinsp_dns_manager const&) = delete;

~sinsp_dns_manager() {
cleanup();
Copy link
Contributor

Choose a reason for hiding this comment

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

note: cleanup is idempotent:

void sinsp_dns_manager::cleanup()
{
	if(m_resolver)
	{
		m_exit_signal.set_value();
		m_resolver->join();
		m_resolver = NULL;
		m_exit_signal = std::promise<void>();
	}
}

LGTM :)

}

sinsp_dns_manager(sinsp_dns_manager const&) = delete;
void operator=(sinsp_dns_manager const&) = delete;

#if defined(HAS_CAPTURE) && !defined(CYGWING_AGENT) && !defined(_WIN32) && !defined(__EMSCRIPTEN__)
struct dns_info
Expand Down