Fix mem leak on errors.
This commit is contained in:
Simon Josefsson
2007-01-18 11:37:32 +00:00
parent a0eda7365e
commit 576d37dafd

View File

@@ -104,7 +104,8 @@ int _libssh2_dsa_new(libssh2_dsa_ctx **dsactx,
{ {
int rc; int rc;
rc = gcry_sexp_build (dsactx, NULL, "(public-key(dsa(p%b)(q%b)(g%b)(y%b)))", rc = gcry_sexp_build (dsactx, NULL,
"(public-key(dsa(p%b)(q%b)(g%b)(y%b)))",
p_len, p, q_len, q, g_len, g, y_len, y); p_len, p, q_len, q, g_len, g, y_len, y);
if (rc) if (rc)
{ {
@@ -158,8 +159,9 @@ int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
unsigned char *secret, unsigned char *secret,
int encrypt) int encrypt)
{ {
int mode = 0, keylen, err; int mode = 0, err;
keylen = gcry_cipher_get_algo_keylen (algo); int keylen = gcry_cipher_get_algo_keylen (algo);
if (algo != GCRY_CIPHER_ARCFOUR) if (algo != GCRY_CIPHER_ARCFOUR)
{ {
mode = GCRY_CIPHER_MODE_CBC; mode = GCRY_CIPHER_MODE_CBC;
@@ -174,6 +176,7 @@ int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
err = gcry_cipher_setkey (*h, secret, keylen); err = gcry_cipher_setkey (*h, secret, keylen);
if (err) if (err)
{ {
gcry_cipher_close (*h);
return -1; return -1;
} }
@@ -183,6 +186,7 @@ int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
err = gcry_cipher_setiv (*h, iv, blklen); err = gcry_cipher_setiv (*h, iv, blklen);
if (err) if (err)
{ {
gcry_cipher_close (*h);
return -1; return -1;
} }
} }