summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2013-03-20 22:20:25 +0100
committerStef Walter <stefw@gnome.org>2013-03-20 22:22:30 +0100
commit4b09d2b4d3958b58b020c1ae21fcd932e1eb6c37 (patch)
treeabba9eb25d2d7d4c9804ba56741e08e40b0fe417
parent57d8f36a6cfbde5a9a783f11f2b75f19005c23e1 (diff)
Fix memory leaks reported by 'make leakcheck'
-rw-r--r--common/mock.c4
-rw-r--r--common/pem.c1
-rw-r--r--common/tests/test-hash.c2
-rw-r--r--common/tests/test-utf8.c4
-rw-r--r--common/tests/test-x509.c1
-rw-r--r--p11-kit/iter.c3
-rw-r--r--p11-kit/tests/pin-test.c1
-rw-r--r--p11-kit/tests/test-iter.c1
-rw-r--r--p11-kit/tests/test-modules.c2
-rw-r--r--p11-kit/uri.c5
-rw-r--r--tools/extract-openssl.c3
-rw-r--r--tools/tests/test-openssl.c7
-rw-r--r--tools/tests/test-pem.c6
-rw-r--r--tools/tests/test-save.c2
-rw-r--r--tools/tests/test-x509.c3
-rw-r--r--trust/builder.c2
-rw-r--r--trust/index.c7
-rw-r--r--trust/module.c5
-rw-r--r--trust/session.c1
-rw-r--r--trust/tests/test-builder.c51
-rw-r--r--trust/tests/test-index.c5
-rw-r--r--trust/tests/test-module.c2
22 files changed, 91 insertions, 27 deletions
diff --git a/common/mock.c b/common/mock.c
index 3ba3085..9d6c960 100644
--- a/common/mock.c
+++ b/common/mock.c
@@ -119,8 +119,10 @@ static void
free_session (void *data)
{
Session *sess = (Session *)data;
- if (sess)
+ if (sess) {
p11_dict_free (sess->objects);
+ p11_array_free (sess->matches);
+ }
free (sess);
}
diff --git a/common/pem.c b/common/pem.c
index b3c6acd..b0625ef 100644
--- a/common/pem.c
+++ b/common/pem.c
@@ -227,6 +227,7 @@ p11_pem_parse (const char *data,
if (sink != NULL)
(sink) (type, decoded, n_decoded, user_data);
++nfound;
+ free (decoded);
}
}
diff --git a/common/tests/test-hash.c b/common/tests/test-hash.c
index d6d7990..c8694e1 100644
--- a/common/tests/test-hash.c
+++ b/common/tests/test-hash.c
@@ -89,6 +89,8 @@ test_sha1_long (CuTest *cu)
p11_hash_sha1 (checksum, input, 1000000, NULL);
CuAssertTrue (cu, memcmp (expected, checksum, P11_HASH_SHA1_LEN) == 0);
+
+ free (input);
}
const char *md5_input[] = {
diff --git a/common/tests/test-utf8.c b/common/tests/test-utf8.c
index d34f597..ed13fa2 100644
--- a/common/tests/test-utf8.c
+++ b/common/tests/test-utf8.c
@@ -38,6 +38,7 @@
#include "utf8.h"
#include <stdio.h>
+#include <stdlib.h>
#define ELEMS(x) (sizeof (x) / sizeof (x[0]))
@@ -74,6 +75,7 @@ test_ucs2be (CuTest *cu)
CuAssertIntEquals (cu, fixtures[i].output_len, length);
CuAssertStrEquals (cu, fixtures[i].output, output);
+ free (output);
}
}
@@ -146,6 +148,8 @@ test_ucs4be (CuTest *cu)
CuAssertIntEquals (cu, fixtures[i].output_len, length);
CuAssertStrEquals (cu, fixtures[i].output, output);
+
+ free (output);
}
}
diff --git a/common/tests/test-x509.c b/common/tests/test-x509.c
index 08c269d..2596c9c 100644
--- a/common/tests/test-x509.c
+++ b/common/tests/test-x509.c
@@ -397,6 +397,7 @@ test_directory_string (CuTest *tc)
CuAssertIntEquals (tc, fixtures[i].output_len, length);
CuAssertStrEquals (tc, fixtures[i].output, string);
+ free (string);
}
}
diff --git a/p11-kit/iter.c b/p11-kit/iter.c
index 7f23c53..c144165 100644
--- a/p11-kit/iter.c
+++ b/p11-kit/iter.c
@@ -815,6 +815,7 @@ p11_kit_iter_free (P11KitIter *iter)
finish_iterating (iter, CKR_OK);
p11_array_free (iter->modules);
p11_attrs_free (iter->match_attrs);
+ free (iter->slots);
for (cb = iter->callbacks; cb != NULL; cb = next) {
next = cb->next;
@@ -822,4 +823,6 @@ p11_kit_iter_free (P11KitIter *iter)
(cb->destroyer) (cb->callback_data);
free (cb);
}
+
+ free (iter);
}
diff --git a/p11-kit/tests/pin-test.c b/p11-kit/tests/pin-test.c
index 758acf4..dd020bc 100644
--- a/p11-kit/tests/pin-test.c
+++ b/p11-kit/tests/pin-test.c
@@ -109,7 +109,6 @@ test_pin_read (CuTest *tc)
p11_kit_pin_unregister_callback ("/the/pin_source", callback_one,
&data);
- p11_kit_pin_ref (pin);
p11_kit_pin_unref (pin);
}
diff --git a/p11-kit/tests/test-iter.c b/p11-kit/tests/test-iter.c
index 81aa06c..ccfce2c 100644
--- a/p11-kit/tests/test-iter.c
+++ b/p11-kit/tests/test-iter.c
@@ -983,6 +983,7 @@ test_load_attributes_none (CuTest *tc)
attrs = p11_attrs_buildn (NULL, NULL, 0);
rv = p11_kit_iter_load_attributes (iter, attrs, 0);
CuAssertTrue (tc, rv == CKR_OK);
+ p11_attrs_free (attrs);
}
CuAssertTrue (tc, rv == CKR_CANCEL);
diff --git a/p11-kit/tests/test-modules.c b/p11-kit/tests/test-modules.c
index 5bdbaa4..3f0e4e0 100644
--- a/p11-kit/tests/test-modules.c
+++ b/p11-kit/tests/test-modules.c
@@ -96,6 +96,8 @@ test_no_duplicates (CuTest *tc)
CuAssert (tc, "shouldn't be reached", 0);
if (!p11_dict_set (paths, path, ""))
CuAssert (tc, "shouldn't be reached", 0);
+
+ free (path);
}
p11_dict_free (paths);
diff --git a/p11-kit/uri.c b/p11-kit/uri.c
index 0bb35db..52bd61d 100644
--- a/p11-kit/uri.c
+++ b/p11-kit/uri.c
@@ -922,10 +922,7 @@ parse_class_attribute (const char *name, const char *start, const char *end,
free (value);
- attr.pValue = malloc (sizeof (klass));
- return_val_if_fail (attr.pValue != NULL, P11_KIT_URI_UNEXPECTED);
-
- memcpy (attr.pValue, &klass, sizeof (klass));
+ attr.pValue = &klass;
attr.ulValueLen = sizeof (klass);
attr.type = CKA_CLASS;
diff --git a/tools/extract-openssl.c b/tools/extract-openssl.c
index 8e02421..cf387f7 100644
--- a/tools/extract-openssl.c
+++ b/tools/extract-openssl.c
@@ -602,9 +602,6 @@ p11_extract_openssl_directory (P11KitIter *iter,
p11_buffer_init (&buf, 0);
while ((rv = p11_kit_iter_next (iter)) == CKR_OK) {
- pem = p11_pem_write (ex->cert_der, ex->cert_len, "CERTIFICATE", &length);
- return_val_if_fail (pem != NULL, false);
-
if (!p11_buffer_reset (&buf, 1024))
return_val_if_reached (false);
diff --git a/tools/tests/test-openssl.c b/tools/tests/test-openssl.c
index dc68c19..77df109 100644
--- a/tools/tests/test-openssl.c
+++ b/tools/tests/test-openssl.c
@@ -184,6 +184,7 @@ test_file (CuTest *tc)
test_check_file (tc, test.directory, "extract.pem",
SRCDIR "/files/cacert3-trusted-server-alias.pem");
+ free (test.ex.destination);
teardown (tc);
}
@@ -208,6 +209,7 @@ test_plain (CuTest *tc)
test_check_file (tc, test.directory, "extract.pem",
SRCDIR "/files/cacert3-trusted-alias.pem");
+ free (test.ex.destination);
teardown (tc);
}
@@ -250,6 +252,7 @@ test_keyid (CuTest *tc)
test_check_file (tc, test.directory, "extract.pem",
SRCDIR "/files/cacert3-trusted-keyid.pem");
+ free (test.ex.destination);
teardown (tc);
}
@@ -282,6 +285,7 @@ test_not_authority (CuTest *tc)
test_check_file (tc, test.directory, "extract.pem",
SRCDIR "/files/cacert3-not-trusted.pem");
+ free (test.ex.destination);
teardown (tc);
}
@@ -316,6 +320,7 @@ test_distrust_all (CuTest *tc)
test_check_file (tc, test.directory, "extract.pem",
SRCDIR "/files/cacert3-distrust-all.pem");
+ free (test.ex.destination);
teardown (tc);
}
@@ -347,6 +352,7 @@ test_file_multiple (CuTest *tc)
test_check_file (tc, test.directory, "extract.pem",
SRCDIR "/files/cacert3-trusted-multiple.pem");
+ free (test.ex.destination);
teardown (tc);
}
@@ -369,6 +375,7 @@ test_file_without (CuTest *tc)
test_check_data (tc, test.directory, "extract.pem", "", 0);
+ free (test.ex.destination);
teardown (tc);
}
diff --git a/tools/tests/test-pem.c b/tools/tests/test-pem.c
index 3be8fee..5c19455 100644
--- a/tools/tests/test-pem.c
+++ b/tools/tests/test-pem.c
@@ -135,6 +135,7 @@ test_file (CuTest *tc)
test_check_file (tc, test.directory, "extract.pem", SRCDIR "/files/cacert3.pem");
+ free (test.ex.destination);
teardown (tc);
}
@@ -160,6 +161,7 @@ test_file_multiple (CuTest *tc)
test_check_file (tc, test.directory, "extract.pem", SRCDIR "/files/cacert3-twice.pem");
+ free (test.ex.destination);
teardown (tc);
}
@@ -174,9 +176,6 @@ test_file_without (CuTest *tc)
p11_kit_iter_add_filter (test.iter, certificate_filter, 1);
p11_kit_iter_begin_with (test.iter, &test.module, 0, 0);
- if (asprintf (&test.ex.destination, "%s/%s", test.directory, "extract.cer") < 0)
- assert_not_reached ();
-
if (asprintf (&test.ex.destination, "%s/%s", test.directory, "extract.pem") < 0)
assert_not_reached ();
@@ -185,6 +184,7 @@ test_file_without (CuTest *tc)
test_check_data (tc, test.directory, "extract.pem", "", 0);
+ free (test.ex.destination);
teardown (tc);
}
diff --git a/tools/tests/test-save.c b/tools/tests/test-save.c
index cd6cb44..32713ee 100644
--- a/tools/tests/test-save.c
+++ b/tools/tests/test-save.c
@@ -91,6 +91,8 @@ write_zero_file (CuTest *tc,
CuAssertTrue (tc, fd != -1);
res = close (fd);
CuAssertTrue (tc, res >= 0);
+
+ free (filename);
}
static void
diff --git a/tools/tests/test-x509.c b/tools/tests/test-x509.c
index f3585f1..7cf9787 100644
--- a/tools/tests/test-x509.c
+++ b/tools/tests/test-x509.c
@@ -135,6 +135,7 @@ test_file (CuTest *tc)
test_check_file (tc, test.directory, "extract.cer", SRCDIR "/files/cacert3.der");
+ free (test.ex.destination);
teardown (tc);
}
@@ -166,6 +167,7 @@ test_file_multiple (CuTest *tc)
test_check_file (tc, test.directory, "extract.cer", SRCDIR "/files/cacert3.der");
+ free (test.ex.destination);
teardown (tc);
}
@@ -192,6 +194,7 @@ test_file_without (CuTest *tc)
p11_message_loud ();
+ free (test.ex.destination);
teardown (tc);
}
diff --git a/trust/builder.c b/trust/builder.c
index 93c5f3e..53201ed 100644
--- a/trust/builder.c
+++ b/trust/builder.c
@@ -1159,6 +1159,8 @@ replace_nss_trust_object (p11_builder *builder,
rv = p11_index_replace_all (index, match, CKA_INVALID, array);
return_if_fail (rv == CKR_OK);
p11_array_free (array);
+
+ p11_attrs_free (match);
}
static void
diff --git a/trust/index.c b/trust/index.c
index 1275cd9..c8632cc 100644
--- a/trust/index.c
+++ b/trust/index.c
@@ -293,10 +293,10 @@ index_notify (p11_index *index,
{
index_object *obj;
- if (!index->notify || index->notifying)
- return;
+ if (!index->notify || index->notifying) {
+ p11_attrs_free (removed);
- if (!index->changes) {
+ } else if (!index->changes) {
call_notify (index, handle, removed);
p11_attrs_free (removed);
@@ -373,6 +373,7 @@ p11_index_take (p11_index *index,
rv = index_build (index, &obj->attrs, attrs);
if (rv != CKR_OK) {
p11_attrs_free (attrs);
+ free (obj);
return rv;
}
diff --git a/trust/module.c b/trust/module.c
index a819303..6be2847 100644
--- a/trust/module.c
+++ b/trust/module.c
@@ -188,6 +188,7 @@ create_tokens_inlock (p11_array *tokens,
CK_SLOT_ID slot;
const char *path;
const char *label;
+ char *alloc;
char *remaining;
char *base;
char *pos;
@@ -195,7 +196,7 @@ create_tokens_inlock (p11_array *tokens,
p11_debug ("using paths: %s", paths);
- remaining = strdup (paths);
+ alloc = remaining = strdup (paths);
return_val_if_fail (remaining != NULL, false);
while (remaining) {
@@ -240,7 +241,7 @@ create_tokens_inlock (p11_array *tokens,
}
}
- free (remaining);
+ free (alloc);
return true;
}
diff --git a/trust/session.c b/trust/session.c
index 19434ff..2a8c9f9 100644
--- a/trust/session.c
+++ b/trust/session.c
@@ -77,6 +77,7 @@ p11_session_free (void *data)
p11_session *session = data;
p11_session_set_operation (session, NULL, NULL);
+ p11_builder_free (session->builder);
p11_index_free (session->index);
free (session);
diff --git a/trust/tests/test-builder.c b/trust/tests/test-builder.c
index be5390e..3212bac 100644
--- a/trust/tests/test-builder.c
+++ b/trust/tests/test-builder.c
@@ -429,6 +429,7 @@ test_build_certificate_no_type (CuTest *cu)
};
CK_ATTRIBUTE *attrs;
+ CK_ATTRIBUTE *merge;
CK_RV rv;
setup (cu);
@@ -436,8 +437,10 @@ test_build_certificate_no_type (CuTest *cu)
p11_message_quiet ();
attrs = NULL;
- rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
+ merge = p11_attrs_dup (input);
+ rv = p11_builder_build (test.builder, test.index, &attrs, merge);
CuAssertIntEquals (cu, CKR_TEMPLATE_INCOMPLETE, rv);
+ p11_attrs_free (merge);
p11_message_loud ();
@@ -456,6 +459,7 @@ test_build_certificate_bad_type (CuTest *cu)
};
CK_ATTRIBUTE *attrs;
+ CK_ATTRIBUTE *merge;
CK_RV rv;
setup (cu);
@@ -463,8 +467,10 @@ test_build_certificate_bad_type (CuTest *cu)
p11_message_quiet ();
attrs = NULL;
- rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
+ merge = p11_attrs_dup (input);
+ rv = p11_builder_build (test.builder, test.index, &attrs, merge);
CuAssertIntEquals (cu, CKR_TEMPLATE_INCONSISTENT, rv);
+ p11_attrs_free (merge);
p11_message_loud ();
@@ -524,6 +530,7 @@ test_create_not_settable (CuTest *cu)
};
CK_ATTRIBUTE *attrs;
+ CK_ATTRIBUTE *merge;
CK_RV rv;
setup (cu);
@@ -531,8 +538,10 @@ test_create_not_settable (CuTest *cu)
p11_message_quiet ();
attrs = NULL;
- rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
+ merge = p11_attrs_dup (input);
+ rv = p11_builder_build (test.builder, test.index, &attrs, merge);
CuAssertIntEquals (cu, CKR_ATTRIBUTE_READ_ONLY, rv);
+ p11_attrs_free (merge);
p11_message_loud ();
@@ -587,6 +596,7 @@ test_create_unsupported (CuTest *cu)
};
CK_ATTRIBUTE *attrs;
+ CK_ATTRIBUTE *merge;
CK_RV rv;
setup (cu);
@@ -594,8 +604,10 @@ test_create_unsupported (CuTest *cu)
p11_message_quiet ();
attrs = NULL;
- rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
+ merge = p11_attrs_dup (input);
+ rv = p11_builder_build (test.builder, test.index, &attrs, merge);
CuAssertIntEquals (cu, CKR_TEMPLATE_INCONSISTENT, rv);
+ p11_attrs_free (merge);
p11_message_loud ();
@@ -613,6 +625,7 @@ test_create_generated (CuTest *cu)
};
CK_ATTRIBUTE *attrs;
+ CK_ATTRIBUTE *merge;
CK_RV rv;
setup (cu);
@@ -620,8 +633,10 @@ test_create_generated (CuTest *cu)
p11_message_quiet ();
attrs = NULL;
- rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
+ merge = p11_attrs_dup (input);
+ rv = p11_builder_build (test.builder, test.index, &attrs, merge);
CuAssertIntEquals (cu, CKR_TEMPLATE_INCONSISTENT, rv);
+ p11_attrs_free (merge);
p11_message_loud ();
@@ -639,6 +654,7 @@ test_create_bad_attribute (CuTest *cu)
};
CK_ATTRIBUTE *attrs;
+ CK_ATTRIBUTE *merge;
CK_RV rv;
setup (cu);
@@ -646,8 +662,10 @@ test_create_bad_attribute (CuTest *cu)
p11_message_quiet ();
attrs = NULL;
- rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
+ merge = p11_attrs_dup (input);
+ rv = p11_builder_build (test.builder, test.index, &attrs, merge);
CuAssertIntEquals (cu, CKR_TEMPLATE_INCONSISTENT, rv);
+ p11_attrs_free (merge);
p11_message_loud ();
@@ -663,6 +681,7 @@ test_create_missing_attribute (CuTest *cu)
};
CK_ATTRIBUTE *attrs;
+ CK_ATTRIBUTE *merge;
CK_RV rv;
setup (cu);
@@ -670,8 +689,10 @@ test_create_missing_attribute (CuTest *cu)
p11_message_quiet ();
attrs = NULL;
- rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
+ merge = p11_attrs_dup (input);
+ rv = p11_builder_build (test.builder, test.index, &attrs, merge);
CuAssertIntEquals (cu, CKR_TEMPLATE_INCOMPLETE, rv);
+ p11_attrs_free (merge);
p11_message_loud ();
@@ -687,6 +708,7 @@ test_create_no_class (CuTest *cu)
};
CK_ATTRIBUTE *attrs;
+ CK_ATTRIBUTE *merge;
CK_RV rv;
setup (cu);
@@ -694,8 +716,10 @@ test_create_no_class (CuTest *cu)
p11_message_quiet ();
attrs = NULL;
- rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
+ merge = p11_attrs_dup (input);
+ rv = p11_builder_build (test.builder, test.index, &attrs, merge);
CuAssertIntEquals (cu, CKR_TEMPLATE_INCOMPLETE, rv);
+ p11_attrs_free (merge);
p11_message_loud ();
@@ -712,6 +736,7 @@ test_create_token_mismatch (CuTest *cu)
};
CK_ATTRIBUTE *attrs;
+ CK_ATTRIBUTE *merge;
CK_RV rv;
setup (cu);
@@ -719,8 +744,10 @@ test_create_token_mismatch (CuTest *cu)
p11_message_quiet ();
attrs = NULL;
- rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
+ merge = p11_attrs_dup (input);
+ rv = p11_builder_build (test.builder, test.index, &attrs, merge);
CuAssertIntEquals (cu, CKR_TEMPLATE_INCONSISTENT, rv);
+ p11_attrs_free (merge);
p11_message_loud ();
@@ -800,6 +827,7 @@ test_modify_read_only (CuTest *cu)
merge = p11_attrs_dup (modify);
rv = p11_builder_build (test.builder, test.index, &attrs, merge);
CuAssertIntEquals (cu, CKR_ATTRIBUTE_READ_ONLY, rv);
+ p11_attrs_free (merge);
p11_message_loud ();
@@ -869,6 +897,7 @@ test_modify_not_modifiable (CuTest *cu)
};
CK_ATTRIBUTE *attrs;
+ CK_ATTRIBUTE *merge;
CK_RV rv;
setup (cu);
@@ -879,8 +908,10 @@ test_modify_not_modifiable (CuTest *cu)
p11_message_quiet ();
- rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (modify));
+ merge = p11_attrs_dup (modify);
+ rv = p11_builder_build (test.builder, test.index, &attrs, merge);
CuAssertIntEquals (cu, CKR_ATTRIBUTE_READ_ONLY, rv);
+ p11_attrs_free (merge);
p11_message_loud ();
diff --git a/trust/tests/test-index.c b/trust/tests/test-index.c
index d58a510..14f5a8a 100644
--- a/trust/tests/test-index.c
+++ b/trust/tests/test-index.c
@@ -192,6 +192,7 @@ test_snapshot (CuTest *cu)
for (i = 0; i < NUM; i++)
CuAssertIntEquals (cu, expected[i], snapshot[i]);
+ free (snapshot);
teardown (cu);
}
@@ -229,6 +230,7 @@ test_snapshot_base (CuTest *cu)
for (i = 0; i < NUM * 2; i++)
CuAssertIntEquals (cu, expected[i / 2], snapshot[i]);
+ free (snapshot);
teardown (cu);
}
@@ -665,6 +667,7 @@ test_replace_all (CuTest *tc)
CuAssertTrue (tc, rv == CKR_OK);
CuAssertIntEquals (tc, 0, array->num);
+ p11_array_free (array);
/* eins should have replaced one */
check = p11_index_find (test.index, eins, -1);
@@ -1021,6 +1024,8 @@ test_change_nested (CuTest *cu)
CuAssertTrue (cu, rv == CKR_OK);
p11_index_finish (index);
CuAssertIntEquals (cu, 1, on_change_called);
+
+ p11_index_free (index);
}
int
diff --git a/trust/tests/test-module.c b/trust/tests/test-module.c
index 1d97f9b..1033b05 100644
--- a/trust/tests/test-module.c
+++ b/trust/tests/test-module.c
@@ -431,6 +431,8 @@ check_has_trust_object (CuTest *cu,
check_trust_object_equiv (cu, sessions[0], objects[0], cert);
check_trust_object_hashes (cu, sessions[0], objects[0], cert);
+
+ p11_attrs_free (match);
}
static void