From 5e88fd3e75d0a2dbacbc2ae1ded6588e4fab0ac4 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Wed, 22 Jun 2016 13:49:49 +0200 Subject: [PATCH] fixed reallocation bug --- src/tcpconnected.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/tcpconnected.h b/src/tcpconnected.h index b50b3b1..8701ed3 100644 --- a/src/tcpconnected.h +++ b/src/tcpconnected.h @@ -48,6 +48,13 @@ private: */ TcpInBuffer _in; + /** + * Cached reallocation instruction + * @var size_t + */ + size_t _reallocate = 0; + + /** * Helper method to report an error * @return bool Was an error reported? @@ -162,6 +169,9 @@ public: // restore the buffer as member _in = std::move(buffer); + + // do we have to reallocate? + if (_reallocate) { _in.reallocate(_reallocate); _reallocate = 0; } } // keep same object @@ -201,8 +211,8 @@ public: */ virtual uint16_t reportNegotiate(uint16_t heartbeat) override { - // allocate a buffer that is big enough for the biggest possible frame - _in.reallocate(_connection->maxFrame()); + // remember that we have to reallocated (_in member can not be accessed because it is moved away) + _reallocate = _connection->maxFrame(); // pass to base return TcpState::reportNegotiate(heartbeat);