Skip to content

Commit

Permalink
Set cleanup flags to true where possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimi1010 committed Jul 7, 2024
1 parent 5c23df1 commit b997644
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Examples/IPFragUtil/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void splitIPPacketToFragmentsBySize(pcpp::RawPacket* rawPacket, size_t fragmentS
if (ipLayer->getLayerPayloadSize() <= fragmentSize)
{
pcpp::RawPacket* copyOfRawPacket = new pcpp::RawPacket(*rawPacket);
resultFragments.pushBack(copyOfRawPacket);
resultFragments.pushBack(copyOfRawPacket, true);
return;
}

Expand Down Expand Up @@ -218,7 +218,7 @@ void splitIPPacketToFragmentsBySize(pcpp::RawPacket* rawPacket, size_t fragmentS
newFrag.computeCalculateFields();

// add fragment to result list
resultFragments.pushBack(newFrag.getRawPacket());
resultFragments.pushBack(newFrag.getRawPacket(), true);

// increment offset pointer
curOffset += curFragSize;
Expand Down
2 changes: 1 addition & 1 deletion Examples/XdpExample-FilterTraffic/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void onPacketsArrive(pcpp::RawPacket packets[], uint32_t packetCount, pcpp::XdpD
if (args->sendPacketsTo != nullptr)
{
// add packet to the vector of packets to send
packetsToSend.pushBack(new pcpp::RawPacket(packets[i]));
packetsToSend.pushBack(new pcpp::RawPacket(packets[i]), true);
}

// save packet to file if needed
Expand Down
2 changes: 1 addition & 1 deletion Packet++/header/Asn1Codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ namespace pcpp
{
auto encodedRecord = (*recordIter)->encode();
auto copyRecord = Asn1Record::decode(encodedRecord.data(), encodedRecord.size(), false);
m_SubRecords.pushBack(copyRecord.release());
m_SubRecords.pushBack(std::move(copyRecord));
recordValueLength += encodedRecord.size();
}

Expand Down
2 changes: 1 addition & 1 deletion Packet++/src/Asn1Codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ namespace pcpp
value += subRecord->getTotalLength();
valueLen -= subRecord->getTotalLength();

m_SubRecords.pushBack(subRecord);
m_SubRecords.pushBack(subRecord, true);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Packet++/src/IPReassembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ Packet* IPReassembly::processPacket(Packet* fragment, ReassemblyStatus& status,
newFrag->lastFragment = fragWrapper->isLastFragment();

// store the IPFragment in the out-of-order fragment list
fragData->outOfOrderFragments.pushBack(newFrag);
fragData->outOfOrderFragments.pushBack(newFrag, true);

status = OUT_OF_ORDER_FRAGMENT;
return nullptr;
Expand Down
14 changes: 7 additions & 7 deletions Packet++/src/LdapLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ namespace pcpp {
Asn1OctetStringRecord controlTypeRecord(control.controlType);
if (control.controlValue.empty())
{
controlsSubRecords.pushBack(new Asn1SequenceRecord({&controlTypeRecord}));
controlsSubRecords.pushBack(new Asn1SequenceRecord({&controlTypeRecord}), true);
}
else
{
auto controlValueSize = static_cast<size_t>(control.controlValue.size() / 2);
std::unique_ptr<uint8_t[]> controlValue(new uint8_t[controlValueSize]);
controlValueSize = hexStringToByteArray(control.controlValue, controlValue.get(), controlValueSize);
Asn1OctetStringRecord controlValueRecord(controlValue.get(), controlValueSize);
controlsSubRecords.pushBack(new Asn1SequenceRecord({&controlTypeRecord, &controlValueRecord}));
controlsSubRecords.pushBack(new Asn1SequenceRecord({&controlTypeRecord, &controlValueRecord}), true);
}
}
controlsRecord = std::unique_ptr<Asn1ConstructedRecord>(new Asn1ConstructedRecord(Asn1TagClass::ContextSpecific, 0, controlsSubRecords));
Expand Down Expand Up @@ -462,11 +462,11 @@ namespace pcpp {
if (!saslAuthentication.mechanism.empty())
{
PointerVector<Asn1Record> saslAuthenticationRecords;
saslAuthenticationRecords.pushBack(new Asn1OctetStringRecord(saslAuthentication.mechanism));
saslAuthenticationRecords.pushBack(new Asn1OctetStringRecord(saslAuthentication.mechanism), true);
if (!saslAuthentication.credentials.empty())
{
auto credentialsRecord = new Asn1OctetStringRecord(saslAuthentication.credentials.data(), saslAuthentication.credentials.size());
saslAuthenticationRecords.pushBack(credentialsRecord);
saslAuthenticationRecords.pushBack(credentialsRecord, true);
}

saslAuthenticationRecord = std::unique_ptr<Asn1ConstructedRecord>(
Expand Down Expand Up @@ -660,7 +660,7 @@ namespace pcpp {
PointerVector<Asn1Record> attributeSubRecords;
for (const auto& attribute : attributes)
{
attributeSubRecords.pushBack(new Asn1OctetStringRecord(attribute));
attributeSubRecords.pushBack(new Asn1OctetStringRecord(attribute), true);
}
Asn1SequenceRecord attributesRecord(attributeSubRecords);

Expand Down Expand Up @@ -743,13 +743,13 @@ namespace pcpp {
PointerVector<Asn1Record> valuesSubRecords;
for (const auto& value : attribute.values)
{
valuesSubRecords.pushBack(new Asn1OctetStringRecord(value));
valuesSubRecords.pushBack(new Asn1OctetStringRecord(value), true);
}

Asn1OctetStringRecord typeRecord(attribute.type);
Asn1SetRecord valuesRecord(valuesSubRecords);

attributesSubRecords.pushBack(new Asn1SequenceRecord({&typeRecord, &valuesRecord}));
attributesSubRecords.pushBack(new Asn1SequenceRecord({ &typeRecord, &valuesRecord }), true);
}

Asn1OctetStringRecord objectNameRecord(objectName);
Expand Down
6 changes: 3 additions & 3 deletions Packet++/src/SSLHandshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ SSLClientHelloMessage::SSLClientHelloMessage(uint8_t* data, size_t dataLen, SSLH
}


m_ExtensionList.pushBack(newExt);
m_ExtensionList.pushBack(newExt, true);
curPos += newExt->getTotalLength();
}
}
Expand Down Expand Up @@ -1638,7 +1638,7 @@ SSLServerHelloMessage::SSLServerHelloMessage(uint8_t* data, size_t dataLen, SSLH
break;
}

m_ExtensionList.pushBack(newExt);
m_ExtensionList.pushBack(newExt, true);
curPos += newExt->getTotalLength();
}
}
Expand Down Expand Up @@ -1868,7 +1868,7 @@ SSLCertificateMessage::SSLCertificateMessage(uint8_t* data, size_t dataLen, SSLH

PCPP_LOG_DEBUG("Parsing certificate: pos=" << (int)(curPos-data) << "; len=" << certificateLength);
SSLx509Certificate* newCert = new SSLx509Certificate(curPos, certificateLength, certificateFull);
m_CertificateList.pushBack(newCert);
m_CertificateList.pushBack(newCert, true);

curPos += certificateLength;
}
Expand Down
2 changes: 1 addition & 1 deletion Packet++/src/SSLLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ SSLHandshakeLayer::SSLHandshakeLayer(uint8_t* data, size_t dataLen, Layer* prevL
if (message == nullptr)
break;

m_MessageList.pushBack(message);
m_MessageList.pushBack(message, true);
curPos += message->getMessageLength();
curPosIndex += message->getMessageLength();
}
Expand Down
2 changes: 1 addition & 1 deletion Packet++/src/TcpReassembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ TcpReassembly::ReassemblyStatus TcpReassembly::reassemblePacket(Packet& tcpData)
newTcpFrag->sequence = sequence;
newTcpFrag->timestamp = timestampOfTheReceivedPacket;
memcpy(newTcpFrag->data, tcpLayer->getLayerPayload(), tcpPayloadSize);
tcpReassemblyData->twoSides[sideIndex].tcpFragmentList.pushBack(newTcpFrag);
tcpReassemblyData->twoSides[sideIndex].tcpFragmentList.pushBack(newTcpFrag, true);

PCPP_LOG_DEBUG("Found out-of-order packet and added a new TCP fragment with size " << tcpPayloadSize << " to the out-of-order list of side " << static_cast<int>(sideIndex));
status = OutOfOrderTcpMessageBuffered;
Expand Down
6 changes: 3 additions & 3 deletions Pcap++/src/DpdkDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ uint16_t DpdkDevice::receivePackets(MBufRawPacketVector& rawPacketsArr, uint16_t
struct rte_mbuf* mBuf = mBufArray[index];
MBufRawPacket* newRawPacket = new MBufRawPacket();
newRawPacket->setMBuf(mBuf, time);
rawPacketsArr.pushBack(newRawPacket);
rawPacketsArr.pushBack(newRawPacket, true);
}

return numOfPktsReceived;
Expand Down Expand Up @@ -1129,7 +1129,7 @@ uint16_t DpdkDevice::sendPackets(Packet** packetsArr, uint16_t arrLength, uint16
return 0;
}

mBufVec.pushBack(rawPacket);
mBufVec.pushBack(rawPacket, true);
}
else
{
Expand Down Expand Up @@ -1170,7 +1170,7 @@ uint16_t DpdkDevice::sendPackets(RawPacketVector& rawPacketsVec, uint16_t txQueu
return 0;
}

mBufVec.pushBack(rawPacket);
mBufVec.pushBack(rawPacket, true);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Pcap++/src/KniDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ uint16_t KniDevice::receivePackets(MBufRawPacketVector& rawPacketsArr)
struct rte_mbuf* mBuf = mBufArray[index];
MBufRawPacket* newRawPacket = new MBufRawPacket();
newRawPacket->setMBuf(mBuf, time);
rawPacketsArr.pushBack(newRawPacket);
rawPacketsArr.pushBack(newRawPacket, true);
}

return numOfPktsReceived;
Expand Down
2 changes: 1 addition & 1 deletion Pcap++/src/PcapFileDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int IFileReaderDevice::getNextPackets(RawPacketVector& packetVec, int numOfPacke
bool packetRead = getNextPacket(*newPacket);
if (packetRead)
{
packetVec.pushBack(newPacket);
packetVec.pushBack(newPacket, true);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Pcap++/src/PcapLiveDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void PcapLiveDevice::onPacketArrivesNoCallback(uint8_t* user, const struct pcap_
uint8_t* packetData = new uint8_t[pkthdr->caplen];
memcpy(packetData, packet, pkthdr->caplen);
RawPacket* rawPacketPtr = new RawPacket(packetData, pkthdr->caplen, pkthdr->ts, true, pThis->getLinkType());
pThis->m_CapturedPackets->pushBack(rawPacketPtr);
pThis->m_CapturedPackets->pushBack(rawPacketPtr, true);
}

void PcapLiveDevice::onPacketArrivesBlockingMode(uint8_t* user, const struct pcap_pkthdr* pkthdr, const uint8_t* packet)
Expand Down
2 changes: 1 addition & 1 deletion Pcap++/src/RawSocketDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ int RawSocketDevice::receivePackets(RawPacketVector& packetVec, int timeout, int
RawPacket* rawPacket = new RawPacket();
if (receivePacket(*rawPacket, true, timeoutSec-curSec) == RecvSuccess)
{
packetVec.pushBack(rawPacket);
packetVec.pushBack(rawPacket, true);
packetCount++;
}
else
Expand Down
8 changes: 4 additions & 4 deletions Tests/Packet++Test/Tests/Asn1Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,8 @@ PTF_TEST_CASE(Asn1EncodingTest)
// Sequence initialized with a PointerVector
{
pcpp::PointerVector<pcpp::Asn1Record> subRecords;
subRecords.pushBack(new pcpp::Asn1OctetStringRecord("abcd"));
subRecords.pushBack(new pcpp::Asn1IntegerRecord(1000));
subRecords.pushBack(new pcpp::Asn1OctetStringRecord("abcd"), true);
subRecords.pushBack(new pcpp::Asn1IntegerRecord(1000), true);
pcpp::Asn1SequenceRecord record(subRecords);

uint8_t data[20];
Expand Down Expand Up @@ -657,8 +657,8 @@ PTF_TEST_CASE(Asn1EncodingTest)
// Set initialized with a PointerVector
{
pcpp::PointerVector<pcpp::Asn1Record> subRecords;
subRecords.pushBack(new pcpp::Asn1IntegerRecord(1000));
subRecords.pushBack(new pcpp::Asn1OctetStringRecord("abcd"));
subRecords.pushBack(new pcpp::Asn1IntegerRecord(1000), true);
subRecords.pushBack(new pcpp::Asn1OctetStringRecord("abcd"), true);
pcpp::Asn1SetRecord record(subRecords);

uint8_t data[20];
Expand Down
2 changes: 1 addition & 1 deletion Tests/Pcap++Test/Tests/IPFragmentationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
static void ipReassemblyOnFragmentsClean(const pcpp::IPReassembly::PacketKey* key, void* userCookie)
{
pcpp::PointerVector<pcpp::IPReassembly::PacketKey>* packetsRemoved = (pcpp::PointerVector<pcpp::IPReassembly::PacketKey>*)userCookie;
packetsRemoved->pushBack(key->clone());
packetsRemoved->pushBack(key->clone(), true);
}


Expand Down
2 changes: 1 addition & 1 deletion Tests/Pcap++Test/Tests/LiveDeviceTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ PTF_TEST_CASE(TestSendPackets)
int packetsRead = 0;
while(fileReaderDev.getNextPacket(rawPacketArr[packetsRead]))
{
packetVec.pushBack(new pcpp::Packet(&rawPacketArr[packetsRead]));
packetVec.pushBack(new pcpp::Packet(&rawPacketArr[packetsRead]), true);
packetsRead++;
}

Expand Down

0 comments on commit b997644

Please sign in to comment.