fix(network): use shared pointer for message length in Session::read

- Updated `Session::read` to use `std::shared_ptr` for message length to ensure proper memory handling in async operations.
This commit is contained in:
Kieran Kihn
2025-11-29 18:50:44 +08:00
parent f4f66bb397
commit 3dd07e4b20

View File

@@ -27,9 +27,9 @@ namespace UNO::NETWORK {
void Session::read() void Session::read()
{ {
size_t messageLength; auto messageLength = std::make_shared<size_t>(0);
asio::async_read(socket_, asio::async_read(socket_,
asio::buffer(&messageLength, sizeof(messageLength)), asio::buffer(messageLength.get(), sizeof(size_t)),
[this, self = shared_from_this(), messageLength](const asio::error_code &ec, size_t length) { [this, self = shared_from_this(), messageLength](const asio::error_code &ec, size_t length) {
if (!ec) { if (!ec) {
if (messageLength > 0 && messageLength <= 10 * 1024 * 1024) { if (messageLength > 0 && messageLength <= 10 * 1024 * 1024) {