Improved packet allocation

This commit is contained in:
WolverinDEV 2021-02-07 18:14:14 +01:00
parent 261a237291
commit 7c82007b4e
2 changed files with 5 additions and 3 deletions

View File

@ -160,7 +160,8 @@ namespace ts {
protocol::OutgoingServerPacket* protocol::allocate_outgoing_server_packet(size_t payload_size) {
auto base_size = sizeof(protocol::OutgoingServerPacket) - 1;
auto full_size = base_size + payload_size;
/* Allocate at least one payload byte since we're our payload array of length 1 */
auto full_size = base_size + std::max(payload_size, (size_t) 1);
auto result = (protocol::OutgoingServerPacket*) malloc(full_size);
construct_osp(result);
@ -178,7 +179,8 @@ namespace ts {
protocol::OutgoingClientPacket* protocol::allocate_outgoing_client_packet(size_t payload_size) {
auto base_size = sizeof(protocol::OutgoingClientPacket) - 1;
auto full_size = base_size + payload_size;
/* Allocate at least one payload byte since we're our payload array of length 1 */
auto full_size = base_size + std::max(payload_size, (size_t) 1);
auto result = (protocol::OutgoingClientPacket*) malloc(full_size);
construct_ocp(result);

View File

@ -244,7 +244,7 @@ namespace ts::protocol {
struct OutgoingClientPacket : public OutgoingPacket {
public:
OutgoingClientPacket() = default;
virtual ~OutgoingClientPacket() = default;
~OutgoingClientPacket() override = default;
OutgoingClientPacket* next; /* used within the write/process queue */