DEV9: Use vector for ICMP temp buffer

This commit is contained in:
TheLastRar 2024-07-12 18:21:47 +01:00 committed by lightningterror
parent a1a92920b2
commit 9da3bccca2
1 changed files with 3 additions and 6 deletions

View File

@ -704,20 +704,17 @@ namespace Sessions
{ {
// Copy the original packet into the returned ICMP packet // Copy the original packet into the returned ICMP packet
// Allocate fullsize buffer // Allocate fullsize buffer
u8* temp = new u8[ping->originalPacket->GetLength()]; std::vector<u8> temp = std::vector<u8>(ping->originalPacket->GetLength());
// Allocate returned ICMP payload // Allocate returned ICMP payload
int responseSize = ping->originalPacket->GetHeaderLength() + 8; int responseSize = ping->originalPacket->GetHeaderLength() + 8;
data = new PayloadData(responseSize); data = new PayloadData(responseSize);
// Write packet into buffer // Write packet into buffer
int offset = 0; int offset = 0;
ping->originalPacket->WriteBytes(temp, &offset); ping->originalPacket->WriteBytes(temp.data(), &offset);
// Copy only needed bytes // Copy only needed bytes
memcpy(data->data.get(), temp, responseSize); memcpy(data->data.get(), temp.data(), responseSize);
// Cleanup
delete[] temp;
} }
std::unique_ptr<ICMP_Packet> pRet = std::make_unique<ICMP_Packet>(data); std::unique_ptr<ICMP_Packet> pRet = std::make_unique<ICMP_Packet>(data);