Use shared_ptr for encapsulation data instead of raw pointer

This commit is contained in:
Tim Wojtulewicz 2020-10-12 13:15:52 -07:00
parent a7d4364334
commit 41dcd0cde0
16 changed files with 103 additions and 115 deletions

View file

@ -119,11 +119,21 @@ Connection::Connection(NetSessions* s, const detail::ConnIDKey& k, double t,
++total_connections;
if ( arg_encap )
encapsulation = new EncapsulationStack(*arg_encap);
encapsulation = std::make_unique<EncapsulationStack>(*arg_encap);
else
encapsulation = nullptr;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Connection::Connection(NetSessions* s, const detail::ConnIDKey& k, double t,
const ConnID* id, uint32_t flow, const Packet* pkt)
: Connection(s, k, t, id, flow, pkt, pkt->encap.get())
{
}
#pragma GCC diagnostic pop
Connection::~Connection()
{
if ( ! finished )
@ -135,12 +145,11 @@ Connection::~Connection()
conn_val->SetOrigin(nullptr);
delete root_analyzer;
delete encapsulation;
--current_connections;
}
void Connection::CheckEncapsulation(const EncapsulationStack* arg_encap)
void Connection::CheckEncapsulation(const std::shared_ptr<EncapsulationStack>& arg_encap)
{
if ( encapsulation && arg_encap )
{
@ -150,8 +159,7 @@ void Connection::CheckEncapsulation(const EncapsulationStack* arg_encap)
EnqueueEvent(tunnel_changed, nullptr, ConnVal(),
arg_encap->ToVal());
delete encapsulation;
encapsulation = new EncapsulationStack(*arg_encap);
encapsulation = std::make_shared<EncapsulationStack>(*arg_encap);
}
}
@ -163,7 +171,6 @@ void Connection::CheckEncapsulation(const EncapsulationStack* arg_encap)
EnqueueEvent(tunnel_changed, nullptr, ConnVal(), empty.ToVal());
}
delete encapsulation;
encapsulation = nullptr;
}
@ -172,7 +179,7 @@ void Connection::CheckEncapsulation(const EncapsulationStack* arg_encap)
if ( tunnel_changed )
EnqueueEvent(tunnel_changed, nullptr, ConnVal(), arg_encap->ToVal());
encapsulation = new EncapsulationStack(*arg_encap);
encapsulation = std::make_shared<EncapsulationStack>(*arg_encap);
}
}