From e705456f9b69c81432a8030f05fa72bbd4c27b21 Mon Sep 17 00:00:00 2001 From: Melissa Kilby Date: Thu, 30 Nov 2023 05:16:05 +0000 Subject: [PATCH] fix(libsinsp): memleak in sinsp_dns_manager LeakSanitizer: detected memory leaks Direct leak of 8 byte(s) in 1 object(s) allocated from: ... 0x7f84317d54c8 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:95 ... 0x56319abb44cc in sinsp_dns_manager::match(char const*, int, void*, unsigned long) /build/falcosecurity-libs-repo/falcosecurity-libs-prefix/src/falcosecurity-libs/userspace/libsinsp/dns_manager.cpp:121 add destructor to class sinsp_dns_manager to ensure m_resolver is always released when the object goes out of scope Signed-off-by: Melissa Kilby --- userspace/libsinsp/dns_manager.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/userspace/libsinsp/dns_manager.h b/userspace/libsinsp/dns_manager.h index bd5193cc85..4e3bf75fd5 100644 --- a/userspace/libsinsp/dns_manager.h +++ b/userspace/libsinsp/dns_manager.h @@ -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) { @@ -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(); + } + + 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