From 38d15fc9b788e2c904705d2ba8de4d5f1ff7988d Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sun, 18 Apr 2021 10:27:04 +0200 Subject: Codechange: move the logic shrinking of the packets into the Packet itself --- src/network/core/packet.cpp | 5 +++++ src/network/core/tcp.cpp | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/network') diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp index 5cb6716bc..6e6bb51c0 100644 --- a/src/network/core/packet.cpp +++ b/src/network/core/packet.cpp @@ -73,6 +73,11 @@ void Packet::PrepareToSend() this->buffer[1] = GB(this->size, 8, 8); this->pos = 0; // We start reading from here + + /* Reallocate the packet as in 99+% of the times we send at most 25 bytes and + * keeping the other 1400+ bytes wastes memory, especially when someone tries + * to do a denial of service attack! */ + this->buffer = ReallocT(this->buffer, this->size); } /** diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp index ab18f47a8..c779beb96 100644 --- a/src/network/core/tcp.cpp +++ b/src/network/core/tcp.cpp @@ -65,11 +65,6 @@ void NetworkTCPSocketHandler::SendPacket(Packet *packet) packet->PrepareToSend(); - /* Reallocate the packet as in 99+% of the times we send at most 25 bytes and - * keeping the other 1400+ bytes wastes memory, especially when someone tries - * to do a denial of service attack! */ - packet->buffer = ReallocT(packet->buffer, packet->size); - /* Locate last packet buffered for the client */ p = this->packet_queue; if (p == nullptr) { -- cgit v1.2.3-70-g09d2