summaryrefslogtreecommitdiff
path: root/src/network/core/packet.cpp
diff options
context:
space:
mode:
authorRubidium <rubidium@openttd.org>2021-04-18 10:27:04 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-04-24 20:42:01 +0200
commit38d15fc9b788e2c904705d2ba8de4d5f1ff7988d (patch)
tree3c6f0542a968916b1ac78463cc00a97c9497d2e9 /src/network/core/packet.cpp
parentd4f027c03bfc5f632b7d63c125dfa57a7ba89926 (diff)
downloadopenttd-38d15fc9b788e2c904705d2ba8de4d5f1ff7988d.tar.xz
Codechange: move the logic shrinking of the packets into the Packet itself
Diffstat (limited to 'src/network/core/packet.cpp')
-rw-r--r--src/network/core/packet.cpp5
1 files changed, 5 insertions, 0 deletions
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);
}
/**