Fixed memory leak in VirtualTap. Used unique_ptr instead of new/delete pair

This commit is contained in:
Joseph Henry
2017-09-17 23:13:33 -07:00
parent 854dbd7947
commit ed51f41b47
2 changed files with 4 additions and 2 deletions

View File

@@ -719,10 +719,11 @@ namespace ZeroTier {
Mutex::Lock _l(_tcpconns_m); Mutex::Lock _l(_tcpconns_m);
std::time_t current_ts = std::time(nullptr); std::time_t current_ts = std::time(nullptr);
if (current_ts > last_housekeeping_ts + ZT_HOUSEKEEPING_INTERVAL) { if (current_ts > last_housekeeping_ts + ZT_HOUSEKEEPING_INTERVAL) {
DEBUG_EXTRA();
// update managed routes (add/del from network stacks) // update managed routes (add/del from network stacks)
ZeroTier::OneService *service = ((ZeroTier::OneService *)zt1ServiceRef); ZeroTier::OneService *service = ((ZeroTier::OneService *)zt1ServiceRef);
if (service) { if (service) {
std::vector<ZT_VirtualNetworkRoute> *managed_routes = service->getRoutes(this->_nwid); std::unique_ptr<std::vector<ZT_VirtualNetworkRoute>> managed_routes(service->getRoutes(this->_nwid));
ZeroTier::InetAddress target_addr; ZeroTier::InetAddress target_addr;
ZeroTier::InetAddress via_addr; ZeroTier::InetAddress via_addr;
ZeroTier::InetAddress null_addr; ZeroTier::InetAddress null_addr;
@@ -772,6 +773,7 @@ namespace ZeroTier {
} }
} }
} }
// TODO: Clean up VirtualSocket objects // TODO: Clean up VirtualSocket objects
last_housekeeping_ts = std::time(nullptr); last_housekeeping_ts = std::time(nullptr);
} }

View File

@@ -251,7 +251,7 @@ namespace ZeroTier {
* Timestamp of last run of housekeeping * Timestamp of last run of housekeeping
* SEE: ZT_HOUSEKEEPING_INTERVAL in libzt.h * 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 */ /* In these, we will call the stack's corresponding functions, this is */