diff --git a/Examples/IPFragUtil/main.cpp b/Examples/IPFragUtil/main.cpp index 27ad037f97..622bef477e 100644 --- a/Examples/IPFragUtil/main.cpp +++ b/Examples/IPFragUtil/main.cpp @@ -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; } @@ -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; diff --git a/Examples/XdpExample-FilterTraffic/main.cpp b/Examples/XdpExample-FilterTraffic/main.cpp index 747984737d..2a8b0b7954 100644 --- a/Examples/XdpExample-FilterTraffic/main.cpp +++ b/Examples/XdpExample-FilterTraffic/main.cpp @@ -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 diff --git a/Packet++/header/Asn1Codec.h b/Packet++/header/Asn1Codec.h index 7eeb48a526..81ef57f1c2 100644 --- a/Packet++/header/Asn1Codec.h +++ b/Packet++/header/Asn1Codec.h @@ -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(); } diff --git a/Packet++/src/Asn1Codec.cpp b/Packet++/src/Asn1Codec.cpp index 555b829861..228a81f115 100644 --- a/Packet++/src/Asn1Codec.cpp +++ b/Packet++/src/Asn1Codec.cpp @@ -507,7 +507,7 @@ namespace pcpp value += subRecord->getTotalLength(); valueLen -= subRecord->getTotalLength(); - m_SubRecords.pushBack(subRecord); + m_SubRecords.pushBack(subRecord, true); } } diff --git a/Packet++/src/IPReassembly.cpp b/Packet++/src/IPReassembly.cpp index 95bbb48bab..5c29cb3cdf 100644 --- a/Packet++/src/IPReassembly.cpp +++ b/Packet++/src/IPReassembly.cpp @@ -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; diff --git a/Packet++/src/LdapLayer.cpp b/Packet++/src/LdapLayer.cpp index 5874c2a5e5..9e19917598 100644 --- a/Packet++/src/LdapLayer.cpp +++ b/Packet++/src/LdapLayer.cpp @@ -214,7 +214,7 @@ namespace pcpp { Asn1OctetStringRecord controlTypeRecord(control.controlType); if (control.controlValue.empty()) { - controlsSubRecords.pushBack(new Asn1SequenceRecord({&controlTypeRecord})); + controlsSubRecords.pushBack(new Asn1SequenceRecord({&controlTypeRecord}), true); } else { @@ -222,7 +222,7 @@ namespace pcpp { std::unique_ptr 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(new Asn1ConstructedRecord(Asn1TagClass::ContextSpecific, 0, controlsSubRecords)); @@ -462,11 +462,11 @@ namespace pcpp { if (!saslAuthentication.mechanism.empty()) { PointerVector 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( @@ -660,7 +660,7 @@ namespace pcpp { PointerVector attributeSubRecords; for (const auto& attribute : attributes) { - attributeSubRecords.pushBack(new Asn1OctetStringRecord(attribute)); + attributeSubRecords.pushBack(new Asn1OctetStringRecord(attribute), true); } Asn1SequenceRecord attributesRecord(attributeSubRecords); @@ -743,13 +743,13 @@ namespace pcpp { PointerVector 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); diff --git a/Packet++/src/SSLHandshake.cpp b/Packet++/src/SSLHandshake.cpp index 6da7cc21ab..3f1838a224 100644 --- a/Packet++/src/SSLHandshake.cpp +++ b/Packet++/src/SSLHandshake.cpp @@ -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(); } } @@ -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(); } } @@ -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; } diff --git a/Packet++/src/SSLLayer.cpp b/Packet++/src/SSLLayer.cpp index 422d0938e2..d53d0b0a19 100644 --- a/Packet++/src/SSLLayer.cpp +++ b/Packet++/src/SSLLayer.cpp @@ -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(); } diff --git a/Packet++/src/TcpReassembly.cpp b/Packet++/src/TcpReassembly.cpp index 3a696abf43..82bf16ba83 100644 --- a/Packet++/src/TcpReassembly.cpp +++ b/Packet++/src/TcpReassembly.cpp @@ -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(sideIndex)); status = OutOfOrderTcpMessageBuffered; diff --git a/Pcap++/src/DpdkDevice.cpp b/Pcap++/src/DpdkDevice.cpp index 27e6bec5a7..347c443673 100644 --- a/Pcap++/src/DpdkDevice.cpp +++ b/Pcap++/src/DpdkDevice.cpp @@ -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; @@ -1129,7 +1129,7 @@ uint16_t DpdkDevice::sendPackets(Packet** packetsArr, uint16_t arrLength, uint16 return 0; } - mBufVec.pushBack(rawPacket); + mBufVec.pushBack(rawPacket, true); } else { @@ -1170,7 +1170,7 @@ uint16_t DpdkDevice::sendPackets(RawPacketVector& rawPacketsVec, uint16_t txQueu return 0; } - mBufVec.pushBack(rawPacket); + mBufVec.pushBack(rawPacket, true); } else { diff --git a/Pcap++/src/KniDevice.cpp b/Pcap++/src/KniDevice.cpp index 8dd37d47d7..af9208ba8f 100644 --- a/Pcap++/src/KniDevice.cpp +++ b/Pcap++/src/KniDevice.cpp @@ -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; diff --git a/Pcap++/src/PcapFileDevice.cpp b/Pcap++/src/PcapFileDevice.cpp index 82e1f59870..03513f2323 100644 --- a/Pcap++/src/PcapFileDevice.cpp +++ b/Pcap++/src/PcapFileDevice.cpp @@ -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 { diff --git a/Pcap++/src/PcapLiveDevice.cpp b/Pcap++/src/PcapLiveDevice.cpp index a2e1a79c8b..2f3ffa524b 100644 --- a/Pcap++/src/PcapLiveDevice.cpp +++ b/Pcap++/src/PcapLiveDevice.cpp @@ -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) diff --git a/Pcap++/src/RawSocketDevice.cpp b/Pcap++/src/RawSocketDevice.cpp index 4b68849d37..85cf3b7b90 100644 --- a/Pcap++/src/RawSocketDevice.cpp +++ b/Pcap++/src/RawSocketDevice.cpp @@ -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 diff --git a/Tests/Packet++Test/Tests/Asn1Tests.cpp b/Tests/Packet++Test/Tests/Asn1Tests.cpp index 03b8d3264c..62dfa4d190 100644 --- a/Tests/Packet++Test/Tests/Asn1Tests.cpp +++ b/Tests/Packet++Test/Tests/Asn1Tests.cpp @@ -617,8 +617,8 @@ PTF_TEST_CASE(Asn1EncodingTest) // Sequence initialized with a PointerVector { pcpp::PointerVector 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]; @@ -657,8 +657,8 @@ PTF_TEST_CASE(Asn1EncodingTest) // Set initialized with a PointerVector { pcpp::PointerVector 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]; diff --git a/Tests/Pcap++Test/Tests/IPFragmentationTests.cpp b/Tests/Pcap++Test/Tests/IPFragmentationTests.cpp index b7c3fae859..2776f24fd0 100644 --- a/Tests/Pcap++Test/Tests/IPFragmentationTests.cpp +++ b/Tests/Pcap++Test/Tests/IPFragmentationTests.cpp @@ -10,7 +10,7 @@ static void ipReassemblyOnFragmentsClean(const pcpp::IPReassembly::PacketKey* key, void* userCookie) { pcpp::PointerVector* packetsRemoved = (pcpp::PointerVector*)userCookie; - packetsRemoved->pushBack(key->clone()); + packetsRemoved->pushBack(key->clone(), true); } diff --git a/Tests/Pcap++Test/Tests/LiveDeviceTests.cpp b/Tests/Pcap++Test/Tests/LiveDeviceTests.cpp index 9918945f75..13fe47697b 100644 --- a/Tests/Pcap++Test/Tests/LiveDeviceTests.cpp +++ b/Tests/Pcap++Test/Tests/LiveDeviceTests.cpp @@ -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++; }