[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] addr: Fix possible memleak in find_my_address()



commit 95fc085bf367c1559871b68b3e01f1dc084fab6a
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Mon Jul 6 11:21:41 2020 -0400

    addr: Fix possible memleak in find_my_address()
    
    Unit tests also suffered from a memleak.
    
    Closes #40024
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 src/app/config/resolve_addr.c | 5 +++++
 src/test/test_config.c        | 4 +++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/app/config/resolve_addr.c b/src/app/config/resolve_addr.c
index 8c08c6ec0..808c5ddf0 100644
--- a/src/app/config/resolve_addr.c
+++ b/src/app/config/resolve_addr.c
@@ -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;
   }
 
diff --git a/src/test/test_config.c b/src/test/test_config.c
index c4d6a6efc..045dbde0d 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -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:

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits