From 82f46464f3afa7dde91a37677a1f23dbde9e2362 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 3 Sep 2016 16:29:50 -0400 Subject: [PATCH] prevent double free --- Datagram.cpp | 6 +++--- Datagram.h | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Datagram.cpp b/Datagram.cpp index a3da6527..2247dff1 100644 --- a/Datagram.cpp +++ b/Datagram.cpp @@ -205,12 +205,12 @@ namespace datagram if(lease) { if(tunnel) - return DatagramSession::Info{new i2p::data::IdentHash(lease->tunnelGateway.data()), new i2p::data::IdentHash(tunnel->GetEndpointIdentHash().data()), m_LastUse, m_LastSuccess}; + return DatagramSession::Info{lease->tunnelGateway, tunnel->GetEndpointIdentHash(), m_LastUse, m_LastSuccess}; else - return DatagramSession::Info{new i2p::data::IdentHash(lease->tunnelGateway.data()), nullptr, m_LastUse, m_LastSuccess}; + return DatagramSession::Info{lease->tunnelGateway, nullptr, m_LastUse, m_LastSuccess}; } else if(tunnel) - return DatagramSession::Info{nullptr, new i2p::data::IdentHash(tunnel->GetEndpointIdentHash().data()), m_LastUse, m_LastSuccess}; + return DatagramSession::Info{nullptr, tunnel->GetEndpointIdentHash(), m_LastUse, m_LastSuccess}; else return DatagramSession::Info{nullptr, nullptr, m_LastUse, m_LastSuccess}; } diff --git a/Datagram.h b/Datagram.h index a44133f7..add946f0 100644 --- a/Datagram.h +++ b/Datagram.h @@ -52,6 +52,12 @@ namespace datagram const i2p::data::IdentHash * OBEP; const uint64_t activity; const uint64_t success; + Info() : IBGW(nullptr), OBEP(nullptr), activity(0), success(0) {} + Info(const i2p::data::IdentHash & ibgw, const i2p::data::IdentHash & obep, const uint64_t a, const uint64_t s) : + IBGW(new i2p::data::IdentHash(ibgw.data())), + OBEP(new i2p::data::IdentHash(obep.data())), + activity(a), + success(s) {} ~Info() { if(IBGW) delete IBGW;