Reworked git_cred_ssh_keyfile_passphrase_new method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
diff --git a/src/transports/cred.c b/src/transports/cred.c
index e4d205e..bc37d84 100644
--- a/src/transports/cred.c
+++ b/src/transports/cred.c
@@ -90,48 +90,26 @@ int git_cred_ssh_keyfile_passphrase_new(
{
git_cred_ssh_keyfile_passphrase *c;
- if (!cred)
- return -1;
+ assert(cred && privatekey);
- c = git__malloc(sizeof(git_cred_ssh_keyfile_passphrase));
+ c = git__calloc(1, sizeof(git_cred_ssh_keyfile_passphrase));
GITERR_CHECK_ALLOC(c);
c->parent.credtype = GIT_CREDTYPE_SSH_KEYFILE_PASSPHRASE;
c->parent.free = ssh_keyfile_passphrase_free;
c->privatekey = git__strdup(privatekey);
-
- if (!c->privatekey) {
- git__free(c);
- return -1;
- }
+ GITERR_CHECK_ALLOC(c->privatekey);
if (publickey) {
- c->publickey = git__strdup(publickey);
-
- if (!c->publickey) {
- git__free(c->privatekey);
- git__free(c);
- return -1;
- }
- } else {
- c->publickey = NULL;
- }
-
- if (passphrase) {
- c->passphrase = git__strdup(passphrase);
-
- if (!c->passphrase) {
- git__free(c->privatekey);
- if (c->publickey) {
- git__free(c->publickey);
- }
- git__free(c);
- return -1;
- }
- } else {
- c->passphrase = NULL;
- }
+ c->publickey = git__strdup(publickey);
+ GITERR_CHECK_ALLOC(c->publickey);
+ }
+
+ if (passphrase) {
+ c->passphrase = git__strdup(passphrase);
+ GITERR_CHECK_ALLOC(c->passphrase);
+ }
*cred = &c->parent;
return 0;