diff options
author | Alexander Tkachev | 2016-07-20 14:44:24 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | f743b319633dcd57ea08f5ac86d3daec548d1ab0 (patch) | |
tree | ff02af57d11ce16e01c9adae9df081155f71aee5 /backends/cloud/box | |
parent | 0200694dd050409eec7a30efd8a616ab6b1fdae1 (diff) | |
download | scummvm-rg350-f743b319633dcd57ea08f5ac86d3daec548d1ab0.tar.gz scummvm-rg350-f743b319633dcd57ea08f5ac86d3daec548d1ab0.tar.bz2 scummvm-rg350-f743b319633dcd57ea08f5ac86d3daec548d1ab0.zip |
CLOUD: Fix CloudManager::connectStorage() memory leak
Diffstat (limited to 'backends/cloud/box')
-rw-r--r-- | backends/cloud/box/boxstorage.cpp | 18 | ||||
-rw-r--r-- | backends/cloud/box/boxstorage.h | 3 |
2 files changed, 17 insertions, 4 deletions
diff --git a/backends/cloud/box/boxstorage.cpp b/backends/cloud/box/boxstorage.cpp index 9e036b1187..8162af299c 100644 --- a/backends/cloud/box/boxstorage.cpp +++ b/backends/cloud/box/boxstorage.cpp @@ -56,12 +56,16 @@ BoxStorage::BoxStorage(Common::String accessToken, Common::String refreshToken): _token(accessToken), _refreshToken(refreshToken) {} BoxStorage::BoxStorage(Common::String code) { - getAccessToken(new Common::Callback<BoxStorage, BoolResponse>(this, &BoxStorage::codeFlowComplete), code); + getAccessToken( + new Common::Callback<BoxStorage, BoolResponse>(this, &BoxStorage::codeFlowComplete), + new Common::Callback<BoxStorage, Networking::ErrorResponse>(this, &BoxStorage::codeFlowFailed), + code + ); } BoxStorage::~BoxStorage() {} -void BoxStorage::getAccessToken(BoolCallback callback, Common::String code) { +void BoxStorage::getAccessToken(BoolCallback callback, Networking::ErrorCallback errorCallback, Common::String code) { if (!KEY || !SECRET) loadKeyAndSecret(); bool codeFlow = (code != ""); @@ -72,7 +76,8 @@ void BoxStorage::getAccessToken(BoolCallback callback, Common::String code) { } Networking::JsonCallback innerCallback = new Common::CallbackBridge<BoxStorage, BoolResponse, Networking::JsonResponse>(this, &BoxStorage::tokenRefreshed, callback); - Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(innerCallback, getErrorPrintingCallback(), "https://api.box.com/oauth2/token"); + if (errorCallback == nullptr) errorCallback = getErrorPrintingCallback(); + Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(innerCallback, errorCallback, "https://api.box.com/oauth2/token"); if (codeFlow) { request->addPostField("grant_type=authorization_code"); request->addPostField("code=" + code); @@ -117,6 +122,7 @@ void BoxStorage::tokenRefreshed(BoolCallback callback, Networking::JsonResponse void BoxStorage::codeFlowComplete(BoolResponse response) { if (!response.value) { warning("BoxStorage: failed to get access token through code flow"); + CloudMan.removeStorage(this); return; } @@ -124,6 +130,12 @@ void BoxStorage::codeFlowComplete(BoolResponse response) { ConfMan.flushToDisk(); } +void BoxStorage::codeFlowFailed(Networking::ErrorResponse error) { + debug("Box's code flow failed (%s, %ld):", (error.failed ? "failed" : "interrupted"), error.httpResponseCode); + debug("%s", error.response.c_str()); + CloudMan.removeStorage(this); +} + void BoxStorage::saveConfig(Common::String keyPrefix) { ConfMan.set(keyPrefix + "access_token", _token, ConfMan.kCloudDomain); ConfMan.set(keyPrefix + "refresh_token", _refreshToken, ConfMan.kCloudDomain); diff --git a/backends/cloud/box/boxstorage.h b/backends/cloud/box/boxstorage.h index 51f2a9591c..826d6bef4e 100644 --- a/backends/cloud/box/boxstorage.h +++ b/backends/cloud/box/boxstorage.h @@ -42,6 +42,7 @@ class BoxStorage: public Id::IdStorage { void tokenRefreshed(BoolCallback callback, Networking::JsonResponse response); void codeFlowComplete(BoolResponse response); + void codeFlowFailed(Networking::ErrorResponse error); /** Constructs StorageInfo based on JSON response from cloud. */ void infoInnerCallback(StorageInfoCallback outerCallback, Networking::JsonResponse json); @@ -108,7 +109,7 @@ public: * Use "" in order to refresh token and pass a callback, so you could * continue your work when new token is available. */ - void getAccessToken(BoolCallback callback, Common::String code = ""); + void getAccessToken(BoolCallback callback, Networking::ErrorCallback errorCallback = nullptr, Common::String code = ""); Common::String accessToken() { return _token; } }; |