diff options
| author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2026-01-19 19:31:58 +0100 |
|---|---|---|
| committer | Sander Vrijders <sander@ouroboros.rocks> | 2026-01-23 08:20:27 +0100 |
| commit | 9f2e078c694d375ff7a633e629d05554c873c8dc (patch) | |
| tree | d408b478df97dff2d8c2646cf8680d0a3dd9b0fa /src/lib/crypt | |
| parent | c20c5bfb40bb65d4196bcf97e80acd97496ddda3 (diff) | |
| download | ouroboros-9f2e078c694d375ff7a633e629d05554c873c8dc.tar.gz ouroboros-9f2e078c694d375ff7a633e629d05554c873c8dc.zip | |
lib: Fix memleak in oap tests
The test_oap_piggyback_data was not cleaning up the passed data
correctly.
Also, a FILE * was not properly closed in the openssl
load_pubkey_raw_file_to_der() wrapper. Refactored some fail paths to
make them easier to read.
Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/lib/crypt')
| -rw-r--r-- | src/lib/crypt/openssl.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/lib/crypt/openssl.c b/src/lib/crypt/openssl.c index 71a69c1c..638da209 100644 --- a/src/lib/crypt/openssl.c +++ b/src/lib/crypt/openssl.c @@ -1213,21 +1213,19 @@ int openssl_load_pubkey_file_to_der(const char * path, if (pkey == NULL) goto fail_key; - fclose(fp); - /* Extract public key bytes in DER format */ ret = get_pk_bytes_from_key(pkey, buf); + if (ret < 0) + goto fail_extract; EVP_PKEY_free(pkey); - if (ret < 0) - goto fail_extract; + fclose(fp); return 0; fail_extract: - clrbuf(*buf); - return -1; + EVP_PKEY_free(pkey); fail_key: fclose(fp); fail_file: @@ -1295,6 +1293,7 @@ int openssl_load_pubkey_raw_file(const char * path, memcpy(buf->data, tmp_buf, bytes_read); buf->len = bytes_read; + fclose(fp); return 0; fail_malloc: @@ -1337,8 +1336,6 @@ int openssl_load_privkey_raw_file(const char * path, goto fail_file; bytes_read = fread(tmp_buf, 1, sizeof(tmp_buf), fp); - fclose(fp); - if (bytes_read == 0) goto fail_read; @@ -1355,11 +1352,14 @@ int openssl_load_privkey_raw_file(const char * path, if (pkey == NULL) goto fail_read; + fclose(fp); + *key = (void *) pkey; return 0; fail_read: + fclose(fp); fail_file: *key = NULL; return -1; |
