From ed51f41b47d4b2161abc6800b17ef76a6780aa14 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Sun, 17 Sep 2017 23:13:33 -0700 Subject: [PATCH] Fixed memory leak in VirtualTap. Used unique_ptr instead of new/delete pair --- src/VirtualTap.cpp | 4 +++- src/VirtualTap.hpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/VirtualTap.cpp b/src/VirtualTap.cpp index bc00a77..d0e1b45 100644 --- a/src/VirtualTap.cpp +++ b/src/VirtualTap.cpp @@ -719,10 +719,11 @@ namespace ZeroTier { Mutex::Lock _l(_tcpconns_m); std::time_t current_ts = std::time(nullptr); if (current_ts > last_housekeeping_ts + ZT_HOUSEKEEPING_INTERVAL) { + DEBUG_EXTRA(); // update managed routes (add/del from network stacks) ZeroTier::OneService *service = ((ZeroTier::OneService *)zt1ServiceRef); if (service) { - std::vector *managed_routes = service->getRoutes(this->_nwid); + std::unique_ptr> managed_routes(service->getRoutes(this->_nwid)); ZeroTier::InetAddress target_addr; ZeroTier::InetAddress via_addr; ZeroTier::InetAddress null_addr; @@ -772,6 +773,7 @@ namespace ZeroTier { } } } + // TODO: Clean up VirtualSocket objects last_housekeeping_ts = std::time(nullptr); } diff --git a/src/VirtualTap.hpp b/src/VirtualTap.hpp index 90d2f80..3304098 100644 --- a/src/VirtualTap.hpp +++ b/src/VirtualTap.hpp @@ -251,7 +251,7 @@ namespace ZeroTier { * Timestamp of last run of housekeeping * SEE: ZT_HOUSEKEEPING_INTERVAL in libzt.h */ - std::time_t last_housekeeping_ts; + std::time_t last_housekeeping_ts = 0; /****************************************************************************/ /* In these, we will call the stack's corresponding functions, this is */