[tor-commits] [tor/master] Clean up nonsensical calling convention for config_load_geoip_file_

nickm at torproject.org nickm at torproject.org
Mon Nov 5 02:51:56 UTC 2012


commit 98204729aafbbce550fd51dd601690cf60226e60
Author: Nick Mathewson <nickm at torproject.org>
Date:   Sun Nov 4 21:51:02 2012 -0500

    Clean up nonsensical calling convention for config_load_geoip_file_
    
    (How many "load a file" functions do you typically see where the
    function frees the filename argument?)
---
 src/or/config.c |   33 ++++++++++++++++++---------------
 1 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/or/config.c b/src/or/config.c
index be91440..338c670 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -5566,27 +5566,28 @@ parse_outbound_addresses(or_options_t *options, int validate_only, char **msg)
 }
 
 /** Load one of the geoip files, <a>family</a> determining which
- * one. Note that <a>fname</a> will be freed by this
- * function. <a>default_fname</a> is used if on Windows and
+ * one. <a>default_fname</a> is used if on Windows and
  * <a>fname</a> equals "<default>". */
 static void
 config_load_geoip_file_(sa_family_t family,
-                        char *fname, /* will be freed */
+                        const char *fname,
                         const char *default_fname)
 {
-  (void)default_fname;
+#ifdef _WIN32
+  char *free_fname = NULL; /* Used to hold any temporary-allocated value */
   /* XXXX Don't use this "<default>" junk; make our filename options
    * understand prefixes somehow. -NM */
-  /* XXXX024 Reload GeoIPFile on SIGHUP. -NM */
-#ifdef _WIN32
-    if (!strcmp(fname, "<default>")) {
-      const char *conf_root = get_windows_conf_root();
-      tor_free(fname);
-      tor_asprintf(&fname, "%s\\%s", conf_root, default_fname);
-    }
+  if (!strcmp(fname, "<default>")) {
+    const char *conf_root = get_windows_conf_root();
+    tor_asprintf(&free_fname, "%s\\%s", conf_root, default_fname);
+    fname = free_fname;
+  }
+  geoip_load_file(family, fname);
+  tor_free(free_fname);
+#else
+  (void)default_fname;
+  geoip_load_file(family, fname);
 #endif
-    geoip_load_file(family, fname);
-    tor_free(fname);
 }
 
 /** Load geoip files for IPv4 and IPv6 if <a>options</a> and
@@ -5595,14 +5596,16 @@ static void
 config_maybe_load_geoip_files_(const or_options_t *options,
                                const or_options_t *old_options)
 {
+  /* XXXX024 Reload GeoIPFile on SIGHUP. -NM */
+
   if (options->GeoIPFile &&
       ((!old_options || !opt_streq(old_options->GeoIPFile,
                                    options->GeoIPFile))
        || !geoip_is_loaded(AF_INET)))
-    config_load_geoip_file_(AF_INET, tor_strdup(options->GeoIPFile), "geoip");
+    config_load_geoip_file_(AF_INET, options->GeoIPFile, "geoip");
   if (options->GeoIPv6File &&
       ((!old_options || !opt_streq(old_options->GeoIPv6File,
                                    options->GeoIPv6File))
        || !geoip_is_loaded(AF_INET6)))
-    config_load_geoip_file_(AF_INET6, tor_strdup(options->GeoIPv6File), "geoip6");
+    config_load_geoip_file_(AF_INET6, options->GeoIPv6File, "geoip6");
 }



More information about the tor-commits mailing list