diff options
author | Stef Walter <stef@thewalter.net> | 2013-07-23 16:45:50 +0200 |
---|---|---|
committer | Stef Walter <stef@thewalter.net> | 2013-07-23 23:06:30 +0200 |
commit | b14fc0351c4dd71c5ca71df77e325d2b2a4c0583 (patch) | |
tree | c4a47c77a977158b8bd4dcc8f478d6bc34ad233b /trust | |
parent | b7cc29a78c3c705374ff25223fe14749ddb076b9 (diff) |
Fix various memory leaks exposed by 'make leakcheck'
Diffstat (limited to 'trust')
-rw-r--r-- | trust/asn1.c | 4 | ||||
-rw-r--r-- | trust/builder.c | 6 | ||||
-rw-r--r-- | trust/extract-openssl.c | 1 | ||||
-rw-r--r-- | trust/index.c | 2 | ||||
-rw-r--r-- | trust/parser.c | 1 | ||||
-rw-r--r-- | trust/tests/Makefile.am | 12 | ||||
-rw-r--r-- | trust/tests/test-asn1.c | 3 | ||||
-rw-r--r-- | trust/tests/test-builder.c | 4 | ||||
-rw-r--r-- | trust/token.c | 10 |
9 files changed, 29 insertions, 14 deletions
diff --git a/trust/asn1.c b/trust/asn1.c index 7ed3b01..dd1812d 100644 --- a/trust/asn1.c +++ b/trust/asn1.c @@ -327,8 +327,10 @@ p11_asn1_cache_take (p11_asn1_cache *cache, { asn1_item *item; - if (cache == NULL) + if (cache == NULL) { + asn1_delete_structure (&node); return; + } return_if_fail (struct_name != NULL); return_if_fail (der != NULL); diff --git a/trust/builder.c b/trust/builder.c index 2daadb3..18c09ad 100644 --- a/trust/builder.c +++ b/trust/builder.c @@ -1018,9 +1018,6 @@ build_for_schema (p11_builder *builder, } } - if (populate && schema->populate) - *extra = schema->populate (builder, index, merge); - /* Validate the result, before committing to the change. */ if (!loading && schema->validate) { rv = (schema->validate) (builder, attrs, merge); @@ -1028,6 +1025,9 @@ build_for_schema (p11_builder *builder, return rv; } + if (populate && schema->populate) + *extra = schema->populate (builder, index, merge); + return CKR_OK; } diff --git a/trust/extract-openssl.c b/trust/extract-openssl.c index c263ba1..1f12f11 100644 --- a/trust/extract-openssl.c +++ b/trust/extract-openssl.c @@ -672,6 +672,7 @@ p11_extract_openssl_directory (P11KitIter *iter, free (filename); free (path); + free (name); } if (!ret) diff --git a/trust/index.c b/trust/index.c index 83f0dc0..83a4503 100644 --- a/trust/index.c +++ b/trust/index.c @@ -352,6 +352,7 @@ index_build (p11_index *index, count = nmerge; memcpy (built, merge, sizeof (CK_ATTRIBUTE) * nmerge); + p11_array_push (stack, merge); merge_attrs (built, &count, *attrs, nattrs, stack); merge_attrs (built, &count, extra, nextra, stack); @@ -367,7 +368,6 @@ index_build (p11_index *index, free (stack->elem[i]); *attrs = built; } else { - p11_attrs_free (merge); p11_attrs_free (extra); free (built); } diff --git a/trust/parser.c b/trust/parser.c index 4129cc0..54d9c15 100644 --- a/trust/parser.c +++ b/trust/parser.c @@ -676,6 +676,7 @@ p11_parser_free (p11_parser *parser) return_if_fail (parser != NULL); p11_persist_free (parser->persist); p11_array_free (parser->parsed); + p11_array_free (parser->formats); if (parser->asn1_owned) p11_dict_free (parser->asn1_defs); free (parser); diff --git a/trust/tests/Makefile.am b/trust/tests/Makefile.am index 5a6c9ec..53775df 100644 --- a/trust/tests/Makefile.am +++ b/trust/tests/Makefile.am @@ -37,6 +37,12 @@ LDADD = \ CHECK_PROGS = \ test-digest \ + test-asn1 \ + test-base64 \ + test-pem \ + test-oid \ + test-utf8 \ + test-x509 \ test-persist \ test-index \ test-parser \ @@ -48,12 +54,6 @@ CHECK_PROGS = \ test-cer \ test-bundle \ test-openssl \ - test-asn1 \ - test-base64 \ - test-pem \ - test-oid \ - test-utf8 \ - test-x509 \ $(NULL) noinst_PROGRAMS = \ diff --git a/trust/tests/test-asn1.c b/trust/tests/test-asn1.c index d5ec131..df75dfd 100644 --- a/trust/tests/test-asn1.c +++ b/trust/tests/test-asn1.c @@ -142,10 +142,11 @@ test_asn1_free (void) asn = p11_asn1_decode (defs, "PKIX1.ExtKeyUsageSyntax", test_eku_server_and_client, sizeof (test_eku_server_and_client), NULL); - assert_ptr_not_null (defs); + assert_ptr_not_null (asn); p11_asn1_free (asn); p11_asn1_free (NULL); + p11_dict_free (defs); } int diff --git a/trust/tests/test-builder.c b/trust/tests/test-builder.c index 1d37924..6e061aa 100644 --- a/trust/tests/test-builder.c +++ b/trust/tests/test-builder.c @@ -766,6 +766,7 @@ test_valid_dates (void) rv = p11_builder_build (test.builder, test.index, attrs, input, &extra); assert_num_eq (CKR_OK, rv); + p11_attrs_free (extra); p11_attrs_free (attrs); attrs = NULL; @@ -773,6 +774,7 @@ test_valid_dates (void) rv = p11_builder_build (test.builder, test.index, attrs, input, &extra); assert_num_eq (CKR_OK, rv); + p11_attrs_free (extra); p11_attrs_free (attrs); } @@ -831,6 +833,7 @@ test_valid_name (void) rv = p11_builder_build (test.builder, test.index, attrs, input, &extra); assert_num_eq (CKR_OK, rv); + p11_attrs_free (extra); p11_attrs_free (attrs); attrs = NULL; @@ -839,6 +842,7 @@ test_valid_name (void) rv = p11_builder_build (test.builder, test.index, attrs, input, &extra); assert_num_eq (CKR_OK, rv); + p11_attrs_free (extra); p11_attrs_free (attrs); } diff --git a/trust/token.c b/trust/token.c index 97b1fc0..1336443 100644 --- a/trust/token.c +++ b/trust/token.c @@ -396,6 +396,7 @@ p11_token_reload (p11_token *token, CK_ATTRIBUTE *attr; struct stat sb; char *origin; + bool ret; attr = p11_attrs_find (attrs, CKA_X_ORIGIN); if (attr == NULL) @@ -410,10 +411,14 @@ p11_token_reload (p11_token *token, } else { p11_message_err (errno, "cannot access trust file: %s", origin); } - return false; + ret = false; + + } else { + ret = loader_load_file (token, origin, &sb) > 0; } - return loader_load_file (token, origin, &sb) > 0; + free (origin); + return ret; } static bool @@ -676,6 +681,7 @@ on_index_store (void *data, p11_buffer_uninit (&buffer); p11_persist_free (persist); + free (other); if (rv == CKR_OK) { if (!p11_save_finish_file (file, &path, true)) |