From 341e75cdfeaeba290e0ecc09c3b635da82663a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Thu, 14 Mar 2019 11:42:19 +0100 Subject: [PATCH] Fix thumbnails sometimes not being resized in the save browser This was because ImageRequest::Finish used its Width and Height members after calling Request::Finish, after which the ImageRequest object may get deleted at any time by RequestManager. One solution to this is to copy (or preferably move) important members to local variables in the Finish functions of objects derived from Request and use only those after calling Request::Finish (or anything that in turn calls that). --- src/client/http/APIRequest.cpp | 3 +++ src/client/http/GetUserInfoRequest.cpp | 3 +++ src/client/http/ImageRequest.cpp | 7 ++++++- src/client/http/SaveUserInfoRequest.cpp | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/client/http/APIRequest.cpp b/src/client/http/APIRequest.cpp index bfc5b7e03..e304d0f27 100644 --- a/src/client/http/APIRequest.cpp +++ b/src/client/http/APIRequest.cpp @@ -20,6 +20,9 @@ namespace http try { ByteString data = Request::Finish(&result.status); + // Note that at this point it's not safe to use any member of the + // APIRequest object as Request::Finish signals RequestManager + // to delete it. Client::Ref().ParseServerReturn(data, result.status, true); if (result.status == 200 && data.size()) { diff --git a/src/client/http/GetUserInfoRequest.cpp b/src/client/http/GetUserInfoRequest.cpp index 009b097b4..71bde9c1d 100644 --- a/src/client/http/GetUserInfoRequest.cpp +++ b/src/client/http/GetUserInfoRequest.cpp @@ -15,6 +15,9 @@ namespace http { std::unique_ptr user_info; auto result = APIRequest::Finish(); + // Note that at this point it's not safe to use any member of the + // GetUserInfoRequest object as Request::Finish signals RequestManager + // to delete it. if (result.document) { auto &user = (*result.document)["User"]; diff --git a/src/client/http/ImageRequest.cpp b/src/client/http/ImageRequest.cpp index d7fd49de8..d04eb08ae 100644 --- a/src/client/http/ImageRequest.cpp +++ b/src/client/http/ImageRequest.cpp @@ -19,7 +19,12 @@ namespace http std::unique_ptr ImageRequest::Finish() { + int width = Width; + int height = Height; ByteString data = Request::Finish(nullptr); + // Note that at this point it's not safe to use any member of the + // ImageRequest object as Request::Finish signals RequestManager + // to delete it. std::unique_ptr vb; if (data.size()) { @@ -35,7 +40,7 @@ namespace http vb = std::unique_ptr(new VideoBuffer(32, 32)); vb->SetCharacter(14, 14, 'x', 255, 255, 255, 255); } - vb->Resize(Width, Height, true); + vb->Resize(width, height, true); } return vb; } diff --git a/src/client/http/SaveUserInfoRequest.cpp b/src/client/http/SaveUserInfoRequest.cpp index fa61defd1..c7d687ef1 100644 --- a/src/client/http/SaveUserInfoRequest.cpp +++ b/src/client/http/SaveUserInfoRequest.cpp @@ -18,6 +18,9 @@ namespace http bool SaveUserInfoRequest::Finish() { auto result = APIRequest::Finish(); + // Note that at this point it's not safe to use any member of the + // SaveUserInfoRequest object as Request::Finish signals RequestManager + // to delete it. if (result.document) { return (*result.document)["Status"].asInt() == 1;