[tor-commits] [tor/master] Fix some harmless/untriggerable memory leaks found by coverity
nickm at torproject.org
nickm at torproject.org
Tue Apr 8 03:20:32 UTC 2014
commit f0bce2dc359dc2b3004af33541b27c495ad731f3
Author: Nick Mathewson <nickm at torproject.org>
Date: Mon Apr 7 23:20:13 2014 -0400
Fix some harmless/untriggerable memory leaks found by coverity
---
changes/cov-leaks | 6 ++++++
src/or/dirserv.c | 16 ++++++++--------
src/test/test_addr.c | 2 +-
src/test/test_util.c | 28 +++++++++++++++-------------
src/tools/tor-gencert.c | 3 +++
5 files changed, 33 insertions(+), 22 deletions(-)
diff --git a/changes/cov-leaks b/changes/cov-leaks
new file mode 100644
index 0000000..302d247
--- /dev/null
+++ b/changes/cov-leaks
@@ -0,0 +1,6 @@
+ o Minor bugfixes:
+ - Resolve some memory leaks found by coverity in the unit tests,
+ on exit in tor-gencert, and on a failure to compute digests
+ for our own keys when generating a v3 networkstatus vote.
+ These leaks should never have affected anyone in practice.
+
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index b6c5dd4..f5994e0 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -2578,14 +2578,6 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
tor_assert(private_key);
tor_assert(cert);
- if (resolve_my_address(LOG_WARN, options, &addr, NULL, &hostname)<0) {
- log_warn(LD_NET, "Couldn't resolve my hostname");
- return NULL;
- }
- if (!hostname || !strchr(hostname, '.')) {
- tor_free(hostname);
- hostname = tor_dup_ip(addr);
- }
if (crypto_pk_get_digest(private_key, signing_key_digest)<0) {
log_err(LD_BUG, "Error computing signing key digest");
return NULL;
@@ -2594,6 +2586,14 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
log_err(LD_BUG, "Error computing identity key digest");
return NULL;
}
+ if (resolve_my_address(LOG_WARN, options, &addr, NULL, &hostname)<0) {
+ log_warn(LD_NET, "Couldn't resolve my hostname");
+ return NULL;
+ }
+ if (!hostname || !strchr(hostname, '.')) {
+ tor_free(hostname);
+ hostname = tor_dup_ip(addr);
+ }
if (options->VersioningAuthoritativeDir) {
client_versions = format_versions_list(options->RecommendedClientVersions);
diff --git a/src/test/test_addr.c b/src/test/test_addr.c
index eb25e0b..cee2dcf 100644
--- a/src/test/test_addr.c
+++ b/src/test/test_addr.c
@@ -73,7 +73,7 @@ test_addr_basic(void)
}
done:
- ;
+ tor_free(cp);
}
#define test_op_ip6_(a,op,b,e1,e2) \
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 877fa84..08efd45 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -1189,19 +1189,19 @@ test_util_strmisc(void)
}
/* Test str-foo functions */
- cp = tor_strdup("abcdef");
- test_assert(tor_strisnonupper(cp));
- cp[3] = 'D';
- test_assert(!tor_strisnonupper(cp));
- tor_strupper(cp);
- test_streq(cp, "ABCDEF");
- tor_strlower(cp);
- test_streq(cp, "abcdef");
- test_assert(tor_strisnonupper(cp));
- test_assert(tor_strisprint(cp));
- cp[3] = 3;
- test_assert(!tor_strisprint(cp));
- tor_free(cp);
+ cp_tmp = tor_strdup("abcdef");
+ test_assert(tor_strisnonupper(cp_tmp));
+ cp_tmp[3] = 'D';
+ test_assert(!tor_strisnonupper(cp_tmp));
+ tor_strupper(cp_tmp);
+ test_streq(cp_tmp, "ABCDEF");
+ tor_strlower(cp_tmp);
+ test_streq(cp_tmp, "abcdef");
+ test_assert(tor_strisnonupper(cp_tmp));
+ test_assert(tor_strisprint(cp_tmp));
+ cp_tmp[3] = 3;
+ test_assert(!tor_strisprint(cp_tmp));
+ tor_free(cp_tmp);
/* Test memmem and memstr */
{
@@ -2325,6 +2325,8 @@ test_util_listdir(void *ptr)
done:
tor_free(fname1);
tor_free(fname2);
+ tor_free(fname3);
+ tor_free(dir1);
tor_free(dirname);
if (dir_contents) {
SMARTLIST_FOREACH(dir_contents, char *, cp, tor_free(cp));
diff --git a/src/tools/tor-gencert.c b/src/tools/tor-gencert.c
index 2f95cf7..d0c30b8 100644
--- a/src/tools/tor-gencert.c
+++ b/src/tools/tor-gencert.c
@@ -547,6 +547,9 @@ main(int argc, char **argv)
if (signing_key)
EVP_PKEY_free(signing_key);
tor_free(address);
+ tor_free(identity_key_file);
+ tor_free(signing_key_file);
+ tor_free(certificate_file);
crypto_global_cleanup();
return r;
More information about the tor-commits
mailing list