mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 04:13:28 +01:00
addr: Fix possible memleak in find_my_address()
Unit tests also suffered from a memleak. Closes #40024 Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
parent
ac3bc88343
commit
95fc085bf3
@ -204,6 +204,9 @@ get_address_from_config(const or_options_t *options, int warn_severity,
|
||||
if (!tor_addr_lookup(cfg->value, family, &addr)) {
|
||||
tor_addr_copy(addr_out, &addr);
|
||||
*method_out = "RESOLVED";
|
||||
if (*hostname_out) {
|
||||
tor_free(*hostname_out);
|
||||
}
|
||||
*hostname_out = tor_strdup(cfg->value);
|
||||
explicit_ip = false;
|
||||
num_valid_addr++;
|
||||
@ -231,6 +234,7 @@ get_address_from_config(const or_options_t *options, int warn_severity,
|
||||
log_fn(warn_severity, LD_CONFIG,
|
||||
"Found %d Address statement of address family %s. "
|
||||
"Only one is allowed.", num_valid_addr, fmt_af_family(family));
|
||||
tor_free(*hostname_out);
|
||||
return FN_RET_BAIL;
|
||||
}
|
||||
|
||||
@ -241,6 +245,7 @@ get_address_from_config(const or_options_t *options, int warn_severity,
|
||||
* used, custom authorities must be defined else it is a fatal error.
|
||||
* Furthermore, if the Address was resolved to an internal interface, we
|
||||
* stop immediately. */
|
||||
tor_free(*hostname_out);
|
||||
return FN_RET_BAIL;
|
||||
}
|
||||
|
||||
|
@ -1334,6 +1334,7 @@ test_config_find_my_address_mixed(void *arg)
|
||||
retval = find_my_address(options, AF_INET, LOG_NOTICE, &resolved_addr,
|
||||
&method_used, &hostname_out);
|
||||
VALIDATE_FOUND_ADDRESS(true, "RESOLVED", "www.torproject.org.v4");
|
||||
tor_free(hostname_out);
|
||||
|
||||
/* IPv6 address should be found and considered resolved. */
|
||||
tor_addr_parse(&test_addr, "0101::0101");
|
||||
@ -1382,14 +1383,15 @@ test_config_find_my_address_mixed(void *arg)
|
||||
retval = find_my_address(options, AF_INET, LOG_NOTICE, &resolved_addr,
|
||||
&method_used, &hostname_out);
|
||||
VALIDATE_FOUND_ADDRESS(true, "RESOLVED", "www.torproject.org.v4");
|
||||
tor_free(hostname_out);
|
||||
|
||||
/* IPv6 address should be found and considered resolved. */
|
||||
tor_addr_parse(&test_addr, "0101::0101");
|
||||
retval = find_my_address(options, AF_INET6, LOG_NOTICE, &resolved_addr,
|
||||
&method_used, &hostname_out);
|
||||
VALIDATE_FOUND_ADDRESS(true, "CONFIGURED", NULL);
|
||||
|
||||
CLEANUP_FOUND_ADDRESS;
|
||||
|
||||
UNMOCK(tor_addr_lookup);
|
||||
|
||||
done:
|
||||
|
Loading…
Reference in New Issue
Block a user