Skip to content

Commit

Permalink
Use unique_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
seladb committed Jun 25, 2024
1 parent a8f4afd commit baac906
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions Packet++/src/TcpReassembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ void TcpReassembly::checkOutOfOrderFragments(TcpReassemblyData* tcpReassemblyDat
if ((*it)->sequence == tcpReassemblyData->twoSides[sideIndex].sequence)
{
// pop the fragment from fragment list
auto curTcpFrag = tcpReassemblyData->twoSides[sideIndex].tcpFragmentList.getAndRemoveFromVector(it);
auto curTcpFrag = std::unique_ptr<TcpFragment>(tcpReassemblyData->twoSides[sideIndex].tcpFragmentList.getAndRemoveFromVector(it));
// update sequence
tcpReassemblyData->twoSides[sideIndex].sequence += curTcpFrag->dataLength;
if (curTcpFrag->data != nullptr)
Expand All @@ -518,8 +518,6 @@ void TcpReassembly::checkOutOfOrderFragments(TcpReassemblyData* tcpReassemblyDat
}
}

delete curTcpFrag;

foundSomething = true;

continue;
Expand All @@ -529,7 +527,7 @@ void TcpReassembly::checkOutOfOrderFragments(TcpReassemblyData* tcpReassemblyDat
if (SEQ_LT((*it)->sequence, tcpReassemblyData->twoSides[sideIndex].sequence))
{
// pop the fragment from fragment list
auto curTcpFrag = tcpReassemblyData->twoSides[sideIndex].tcpFragmentList.getAndRemoveFromVector(it);
auto curTcpFrag = std::unique_ptr<TcpFragment>(tcpReassemblyData->twoSides[sideIndex].tcpFragmentList.getAndRemoveFromVector(it));
// check if it still has new data
uint32_t newSequence = curTcpFrag->sequence + curTcpFrag->dataLength;

Expand Down Expand Up @@ -559,8 +557,6 @@ void TcpReassembly::checkOutOfOrderFragments(TcpReassemblyData* tcpReassemblyDat
PCPP_LOG_DEBUG("Found a fragment in the out-of-order list which doesn't contain any new data, ignoring it. Fragment size is " << curTcpFrag->dataLength << " on side " << static_cast<int>(sideIndex));
}

delete curTcpFrag;

continue;
}

Expand Down Expand Up @@ -610,7 +606,7 @@ void TcpReassembly::checkOutOfOrderFragments(TcpReassemblyData* tcpReassemblyDat
if (closestSequenceFragIt != tcpReassemblyData->twoSides[sideIndex].tcpFragmentList.end())
{
// get the fragment with the closest sequence
TcpFragment* curTcpFrag = tcpReassemblyData->twoSides[sideIndex].tcpFragmentList.getAndRemoveFromVector(closestSequenceFragIt);
auto curTcpFrag = std::unique_ptr<TcpFragment>(tcpReassemblyData->twoSides[sideIndex].tcpFragmentList.getAndRemoveFromVector(closestSequenceFragIt));

// calculate number of missing bytes
uint32_t missingDataLen = curTcpFrag->sequence - tcpReassemblyData->twoSides[sideIndex].sequence;
Expand Down Expand Up @@ -640,8 +636,6 @@ void TcpReassembly::checkOutOfOrderFragments(TcpReassemblyData* tcpReassemblyDat
}
}

delete curTcpFrag;

PCPP_LOG_DEBUG("Calling checkOutOfOrderFragments again from the start");

// call the method again from the start to do the whole search again (both iterations).
Expand Down

0 comments on commit baac906

Please sign in to comment.