Fix some harmless/untriggerable memory leaks found by coverity

This commit is contained in:
Nick Mathewson 2014-04-07 23:20:13 -04:00
parent 595303fd1e
commit f0bce2dc35
5 changed files with 33 additions and 22 deletions

6
changes/cov-leaks Normal file
View File

@ -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.

View File

@ -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);

View File

@ -73,7 +73,7 @@ test_addr_basic(void)
}
done:
;
tor_free(cp);
}
#define test_op_ip6_(a,op,b,e1,e2) \

View File

@ -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));

View File

@ -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;