summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDariusz Michaluk <d.michaluk@samsung.com>2016-08-30 10:45:21 +0200
committerDariusz Michaluk <d.michaluk@samsung.com>2016-08-31 10:08:38 +0200
commitcf8b1b29a45cf3bec4b8b2265677a7942a18e44b (patch)
tree57c41d8312be46482f66579cbc4a7b4407bf14cf
parent16d271755f6bcb70d6cf66d47d3306a099df5842 (diff)
downloadyaca-cf8b1b29a45cf3bec4b8b2265677a7942a18e44b.tar.gz
yaca-cf8b1b29a45cf3bec4b8b2265677a7942a18e44b.tar.bz2
yaca-cf8b1b29a45cf3bec4b8b2265677a7942a18e44b.zip
Fix yaca_key_import() memory leak.
Change-Id: Iec2ee8d01922e0e4b63fc6963071de3eff0b6979
-rw-r--r--src/key.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/key.c b/src/key.c
index aeaf7a9..fd3be54 100644
--- a/src/key.c
+++ b/src/key.c
@@ -452,8 +452,10 @@ static int import_evp(yaca_key_h *key,
if (pkey == NULL) {
BIO_reset(src);
pkey = PEM_read_bio_PrivateKey(src, NULL, cb, (void*)&cb_data);
- if (ERROR_HANDLE() == YACA_ERROR_INVALID_PASSWORD)
- return YACA_ERROR_INVALID_PASSWORD;
+ if (ERROR_HANDLE() == YACA_ERROR_INVALID_PASSWORD) {
+ ret = YACA_ERROR_INVALID_PASSWORD;
+ goto exit;
+ }
imported_key_category = IMPORTED_KEY_CATEGORY_PRIVATE;
password_supported = true;
}
@@ -491,8 +493,10 @@ static int import_evp(yaca_key_h *key,
if (pkey == NULL) {
BIO_reset(src);
pkey = d2i_PKCS8PrivateKey_bio(src, NULL, cb, (void*)&cb_data);
- if (ERROR_HANDLE() == YACA_ERROR_INVALID_PASSWORD)
- return YACA_ERROR_INVALID_PASSWORD;
+ if (ERROR_HANDLE() == YACA_ERROR_INVALID_PASSWORD) {
+ ret = YACA_ERROR_INVALID_PASSWORD;
+ goto exit;
+ }
imported_key_category = IMPORTED_KEY_CATEGORY_PRIVATE;
password_supported = true;
}
@@ -550,10 +554,10 @@ static int import_evp(yaca_key_h *key,
}
}
- BIO_free(src);
-
- if (pkey == NULL)
- return YACA_ERROR_INVALID_PARAMETER;
+ if (pkey == NULL) {
+ ret = YACA_ERROR_INVALID_PARAMETER;
+ goto exit;
+ }
/* password was given, but it was not required to perform import */
if (password != NULL && !cb_data.password_requested) {
@@ -578,7 +582,8 @@ static int import_evp(yaca_key_h *key,
break;
default:
assert(false);
- return YACA_ERROR_INTERNAL;
+ ret = YACA_ERROR_INTERNAL;
+ goto exit;
}
if (ret != YACA_ERROR_NONE)
goto exit;
@@ -601,7 +606,7 @@ static int import_evp(yaca_key_h *key,
exit:
EVP_PKEY_free(pkey);
-
+ BIO_free_all(src);
return ret;
}