aboutsummaryrefslogtreecommitdiff
path: root/backends/cloud/box/boxstorage.cpp
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-20 14:44:24 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commitf743b319633dcd57ea08f5ac86d3daec548d1ab0 (patch)
treeff02af57d11ce16e01c9adae9df081155f71aee5 /backends/cloud/box/boxstorage.cpp
parent0200694dd050409eec7a30efd8a616ab6b1fdae1 (diff)
downloadscummvm-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/boxstorage.cpp')
-rw-r--r--backends/cloud/box/boxstorage.cpp18
1 files changed, 15 insertions, 3 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);