From dcf0b3576b6fba52ceb5c8164588dc8c7ebb7e5e Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Wed, 4 Nov 2015 13:05:03 +0100 Subject: [PATCH] fix issue when tcp is closed --- src/tcpconnected.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/tcpconnected.h b/src/tcpconnected.h index 02db0ae..95f08b0 100644 --- a/src/tcpconnected.h +++ b/src/tcpconnected.h @@ -125,14 +125,21 @@ public: } else { + // we need a local copy of the buffer - because it is possible that "this" + // object gets destructed halfway through the call to the parse() method + TcpBuffer buffer(std::move(_in)); + // parse the buffer - auto processed = _connection->parse(_in); + auto processed = _connection->parse(buffer); // "this" could be removed by now, check this if (!monitor.valid()) return nullptr; // shrink buffer - _in.shrink(processed); + buffer.shrink(processed); + + // restore the buffer as member + _in.swap(buffer); } }