Skip to content

Commit 098dd4b

Browse files
authored
Removed preemptive cleaning of raw packet. (#1960)
The previous packet data is safely disposed of inside `RawPacket::setRawData` call. The removal of preemptive cleaning also preserves the old data state, in case of operation failure.
1 parent 695b1cd commit 098dd4b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Pcap++/src/PcapFileDevice.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ namespace pcpp
226226

227227
bool PcapFileReaderDevice::getNextPacket(RawPacket& rawPacket)
228228
{
229-
rawPacket.clear();
230229
if (m_PcapDescriptor == nullptr)
231230
{
232231
PCPP_LOG_ERROR("File device '" << m_FileName << "' not opened");
@@ -566,9 +565,6 @@ namespace pcpp
566565

567566
bool PcapNgFileReaderDevice::getNextPacket(RawPacket& rawPacket, std::string& packetComment)
568567
{
569-
rawPacket.clear();
570-
packetComment = "";
571-
572568
if (m_LightPcapNg == nullptr)
573569
{
574570
PCPP_LOG_ERROR("Pcapng file device '" << m_FileName << "' not opened");
@@ -610,7 +606,13 @@ namespace pcpp
610606
}
611607

612608
if (pktHeader.comment != nullptr && pktHeader.comment_length > 0)
609+
{
613610
packetComment = std::string(pktHeader.comment, pktHeader.comment_length);
611+
}
612+
else
613+
{
614+
packetComment.clear();
615+
}
614616

615617
reportPacketProcessed();
616618
return true;
@@ -942,7 +944,6 @@ namespace pcpp
942944

943945
bool SnoopFileReaderDevice::getNextPacket(RawPacket& rawPacket)
944946
{
945-
rawPacket.clear();
946947
if (m_DeviceOpened != true)
947948
{
948949
PCPP_LOG_ERROR("File device '" << m_FileName << "' not opened");

0 commit comments

Comments
 (0)