From 2fed7a944165d30ab2cb192c7984e3dc4ef118d4 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 26 Dec 2017 14:49:25 -0800 Subject: 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 --- core/git-access.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'core') 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); } -- cgit v1.2.3-70-g09d2