1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Fix memory leak in PDU's move assignment operator

Fixes #272
This commit is contained in:
Matias Fontanini
2017-12-14 14:42:46 -03:00
parent 8f85a6e557
commit f44b253a42
2 changed files with 10 additions and 1 deletions

View File

@@ -244,8 +244,9 @@ public:
* \param rhs The PDU to be moved. * \param rhs The PDU to be moved.
*/ */
PDU& operator=(PDU &&rhs) TINS_NOEXCEPT { PDU& operator=(PDU &&rhs) TINS_NOEXCEPT {
delete inner_pdu_;
inner_pdu_ = 0;
std::swap(inner_pdu_, rhs.inner_pdu_); std::swap(inner_pdu_, rhs.inner_pdu_);
rhs.inner_pdu_ = 0;
if (inner_pdu_) { if (inner_pdu_) {
inner_pdu_->parent_pdu(this); inner_pdu_->parent_pdu(this);
} }

View File

@@ -83,6 +83,14 @@ TEST_F(PDUTest, OperatorConcatOnPacket) {
EXPECT_TRUE(std::equal(raw->payload().begin(), raw->payload().end(), raw_payload.begin())); EXPECT_TRUE(std::equal(raw->payload().begin(), raw->payload().end(), raw_payload.begin()));
} }
#if TINS_IS_CXX11
TEST_F(PDUTest, MoveAssignment) {
IP packet = IP("192.168.0.1") / TCP(22, 52);
packet = IP("1.2.3.4");
EXPECT_TRUE(packet.inner_pdu() == 0);
}
#endif // TINS_IS_CXX11
TEST_F(PDUTest, TinsCast) { TEST_F(PDUTest, TinsCast) {
PDU* null_pdu = 0; PDU* null_pdu = 0;
TCP tcp; TCP tcp;