Skip to content

Commit

Permalink
Fix thumbnails sometimes not being resized in the save browser
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
LBPHacker authored and jacob1 committed Mar 19, 2019
1 parent 5916c9d commit 341e75c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/client/http/APIRequest.cpp
Expand Up @@ -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())
{
Expand Down
3 changes: 3 additions & 0 deletions src/client/http/GetUserInfoRequest.cpp
Expand Up @@ -15,6 +15,9 @@ namespace http
{
std::unique_ptr<UserInfo> 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"];
Expand Down
7 changes: 6 additions & 1 deletion src/client/http/ImageRequest.cpp
Expand Up @@ -19,7 +19,12 @@ namespace http

std::unique_ptr<VideoBuffer> 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<VideoBuffer> vb;
if (data.size())
{
Expand All @@ -35,7 +40,7 @@ namespace http
vb = std::unique_ptr<VideoBuffer>(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;
}
Expand Down
3 changes: 3 additions & 0 deletions src/client/http/SaveUserInfoRequest.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 341e75c

Please sign in to comment.