mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 19:55:07 +02:00
make temp copy of NetworkPacket to protect against vector resizing
This commit is contained in:
parent
406d42fe87
commit
318b9b1671
2 changed files with 6 additions and 10 deletions
|
@ -20,7 +20,6 @@ NetworkPacket::NetworkPacket() {
|
|||
|
||||
NetworkPacket::~NetworkPacket() {
|
||||
// nothing to do
|
||||
printf("NetworkPacket::~NetworkPacket() this=%p this.getData()=%p\n", this, getData());
|
||||
}
|
||||
|
||||
void NetworkPacket::copyContents(const sockaddr& address, const unsigned char* packetData, ssize_t packetLength) {
|
||||
|
|
|
@ -31,16 +31,13 @@ bool ReceivedPacketProcessor::process() {
|
|||
usleep(RECEIVED_THREAD_SLEEP_INTERVAL);
|
||||
}
|
||||
while (_packets.size() > 0) {
|
||||
NetworkPacket& packet = _packets.front();
|
||||
|
||||
printf("ReceivedPacketProcessor::process() calling processPacket() NetworkPacket=%p packet.getData()=%p packet.getLength()=%ld\n",
|
||||
&packet, packet.getData(), packet.getLength() );
|
||||
|
||||
processPacket(packet.getAddress(), packet.getData(), packet.getLength());
|
||||
|
||||
lock();
|
||||
_packets.erase(_packets.begin());
|
||||
unlock();
|
||||
lock(); // lock to make sure nothing changes on us
|
||||
NetworkPacket& packet = _packets.front(); // get the oldest packet
|
||||
NetworkPacket temporary = packet; // make a copy of the packet in case the vector is resized on us
|
||||
_packets.erase(_packets.begin()); // remove the oldest packet
|
||||
unlock(); // let others add to the packets
|
||||
processPacket(temporary.getAddress(), temporary.getData(), temporary.getLength()); // process our temporary copy
|
||||
}
|
||||
return isStillRunning(); // keep running till they terminate us
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue