diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2017-12-26 14:49:25 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-12-26 15:57:31 -0800 |
commit | 2fed7a944165d30ab2cb192c7984e3dc4ef118d4 (patch) | |
tree | 2daa7445096deaa993e9caca01414ad77ab416d1 | |
parent | f4237bf843929e30a1ce2976a389b7193597c704 (diff) | |
download | subsurface-2fed7a944165d30ab2cb192c7984e3dc4ef118d4.tar.gz |
Cleanup: avoid memory leak
No point in doing the strdup of the password if we then bail.
Coverity CID 208316
Coverity CID 209293
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | core/git-access.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/core/git-access.c b/core/git-access.c index db35a3083..cabe19e69 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -198,17 +198,15 @@ int credential_ssh_cb(git_cred **out, (void) allowed_types; (void) payload; - const char *priv_key = format_string("%s/%s", system_default_directory(), "ssrf_remote.key"); - const char *passphrase = prefs.cloud_storage_password ? strdup(prefs.cloud_storage_password) : strdup(""); - - /* Bail out from libgit authentication loop when credentials are - * incorrect */ - + /* Bail out from libgit authentication loop when credentials are incorrect */ if (auth_attempt++ > 2) { report_error("Authentication to cloud storage failed."); return GIT_EUSER; } + const char *priv_key = format_string("%s/%s", system_default_directory(), "ssrf_remote.key"); + const char *passphrase = prefs.cloud_storage_password ? strdup(prefs.cloud_storage_password) : strdup(""); + return git_cred_ssh_key_new(out, username_from_url, NULL, priv_key, passphrase); } @@ -222,16 +220,16 @@ int credential_https_cb(git_cred **out, (void) username_from_url; (void) payload; (void) allowed_types; - const char *username = prefs.cloud_storage_email_encoded; - const char *password = prefs.cloud_storage_password ? strdup(prefs.cloud_storage_password) : strdup(""); - - /* Bail out from libgit authentication loop when credentials are - * incorrect */ + /* Bail out from libgit authentication loop when credentials are incorrect */ if (auth_attempt++ > 2) { report_error("Authentication to cloud storage failed."); return GIT_EUSER; } + + const char *username = prefs.cloud_storage_email_encoded; + const char *password = prefs.cloud_storage_password ? strdup(prefs.cloud_storage_password) : strdup(""); + return git_cred_userpass_plaintext_new(out, username, password); } |