From d84a3e75b408fe67982ebae0ece4518310ec593f Mon Sep 17 00:00:00 2001 From: Kyungwook Tak Date: Wed, 25 May 2016 15:33:18 +0900 Subject: [PATCH] Fix crash in onMessageProcess Crash rarely occured when bind dtor in onMessageProcess. Traced by gdb and there's crash when dtor std::vector(RawBuffer) parameter. So don't write code tightly in order to value used as rvalue for automatically moved. Assign lvalues to inbuf/outbuf/task and move it by std::move when needed manually. Change-Id: I2b381331546f1b24c0c500851725376cf100a1cc Signed-off-by: Kyungwook Tak --- src/framework/service/server-service.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/framework/service/server-service.cpp b/src/framework/service/server-service.cpp index c8f5eb7..ac0a98a 100644 --- a/src/framework/service/server-service.cpp +++ b/src/framework/service/server-service.cpp @@ -363,10 +363,16 @@ void ServerService::onMessageProcess(const ConnShPtr &connection) ThrowExc(InternalError, "Message from unknown sock id"); } - m_workqueue.submit(std::bind([this, &connection, process](RawBuffer &buffer) { - connection->send((*process)(connection, buffer)); + auto inbuf = connection->receive(); + auto task = [this, &connection, process](RawBuffer &buffer) { + auto outbuf = (*process)(connection, buffer); + + connection->send(outbuf); + CpuUsageManager::reset(); - }, connection->receive())); + }; + + m_workqueue.submit(std::bind(task, std::move(inbuf))); } } -- 2.7.4