aboutsummaryrefslogtreecommitdiff
path: root/backends/cloud/dropbox
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/dropbox
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/dropbox')
-rw-r--r--backends/cloud/dropbox/dropboxstorage.cpp13
-rw-r--r--backends/cloud/dropbox/dropboxstorage.h1
2 files changed, 12 insertions, 2 deletions
diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp
index e34912ed66..4171af0443 100644
--- a/backends/cloud/dropbox/dropboxstorage.cpp
+++ b/backends/cloud/dropbox/dropboxstorage.cpp
@@ -62,8 +62,9 @@ DropboxStorage::~DropboxStorage() {}
void DropboxStorage::getAccessToken(Common::String code) {
if (!KEY || !SECRET) loadKeyAndSecret();
- Networking::JsonCallback callback = new Common::Callback<DropboxStorage, Networking::JsonResponse>(this, &DropboxStorage::codeFlowComplete);
- Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(callback, nullptr, "https://api.dropboxapi.com/oauth2/token");
+ Networking::JsonCallback callback = new Common::Callback<DropboxStorage, Networking::JsonResponse>(this, &DropboxStorage::codeFlowComplete);
+ Networking::ErrorCallback errorCallback = new Common::Callback<DropboxStorage, Networking::ErrorResponse>(this, &DropboxStorage::codeFlowFailed);
+ Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(callback, errorCallback, "https://api.dropboxapi.com/oauth2/token");
request->addPostField("code=" + code);
request->addPostField("grant_type=authorization_code");
request->addPostField("client_id=" + Common::String(KEY));
@@ -83,6 +84,7 @@ void DropboxStorage::codeFlowComplete(Networking::JsonResponse response) {
if (!result.contains("access_token") || !result.contains("uid")) {
warning("%s", json->stringify(true).c_str());
warning("Bad response, no token/uid passed");
+ CloudMan.removeStorage(this);
} else {
_token = result.getVal("access_token")->asString();
_uid = result.getVal("uid")->asString();
@@ -94,9 +96,16 @@ void DropboxStorage::codeFlowComplete(Networking::JsonResponse response) {
delete json;
} else {
debug("DropboxStorage::codeFlowComplete: got NULL instead of JSON!");
+ CloudMan.removeStorage(this);
}
}
+void DropboxStorage::codeFlowFailed(Networking::ErrorResponse error) {
+ debug("Dropbox's code flow failed (%s, %ld):", (error.failed ? "failed" : "interrupted"), error.httpResponseCode);
+ debug("%s", error.response.c_str());
+ CloudMan.removeStorage(this);
+}
+
void DropboxStorage::saveConfig(Common::String keyPrefix) {
ConfMan.set(keyPrefix + "access_token", _token, ConfMan.kCloudDomain);
ConfMan.set(keyPrefix + "user_id", _uid, ConfMan.kCloudDomain);
diff --git a/backends/cloud/dropbox/dropboxstorage.h b/backends/cloud/dropbox/dropboxstorage.h
index 2c9cf163ab..9dd28ba810 100644
--- a/backends/cloud/dropbox/dropboxstorage.h
+++ b/backends/cloud/dropbox/dropboxstorage.h
@@ -42,6 +42,7 @@ class DropboxStorage: public Cloud::Storage {
void getAccessToken(Common::String code);
void codeFlowComplete(Networking::JsonResponse response);
+ void codeFlowFailed(Networking::ErrorResponse error);
public:
/** This constructor uses OAuth code flow to get tokens. */