[or-cvs] r16779: {tor} Fix numerous memory leaks: some were almost impossible to tr (tor/trunk/src/or)

nickm at seul.org nickm at seul.org
Fri Sep 5 20:52:15 UTC 2008


Author: nickm
Date: 2008-09-05 16:52:15 -0400 (Fri, 05 Sep 2008)
New Revision: 16779

Modified:
   tor/trunk/src/or/config.c
   tor/trunk/src/or/connection_edge.c
   tor/trunk/src/or/directory.c
   tor/trunk/src/or/dirserv.c
   tor/trunk/src/or/policies.c
   tor/trunk/src/or/rendclient.c
   tor/trunk/src/or/rendcommon.c
   tor/trunk/src/or/rendservice.c
Log:
Fix numerous memory leaks: some were almost impossible to trigger, and some almost inevitable.

Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c	2008-09-05 20:18:22 UTC (rev 16778)
+++ tor/trunk/src/or/config.c	2008-09-05 20:52:15 UTC (rev 16779)
@@ -1488,9 +1488,12 @@
 
   next = &list;
   do {
+    k = v = NULL;
     string = parse_config_line_from_str(string, &k, &v);
     if (!string) {
       config_free_lines(list);
+      tor_free(k);
+      tor_free(v);
       return -1;
     }
     if (k && v) {

Modified: tor/trunk/src/or/connection_edge.c
===================================================================
--- tor/trunk/src/or/connection_edge.c	2008-09-05 20:18:22 UTC (rev 16778)
+++ tor/trunk/src/or/connection_edge.c	2008-09-05 20:52:15 UTC (rev 16779)
@@ -717,6 +717,8 @@
       MAP_DEL_CURRENT(address);
     }
   } STRMAP_FOREACH_END;
+
+  tor_free(suffix);
 }
 
 /** Remove all entries from the addressmap that were set via the

Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c	2008-09-05 20:18:22 UTC (rev 16778)
+++ tor/trunk/src/or/directory.c	2008-09-05 20:52:15 UTC (rev 16779)
@@ -3032,7 +3032,7 @@
      * receive anything. */
     write_http_status_line(conn, 400, "Nonauthoritative directory does not "
                            "accept posted server descriptors");
-    return 0;
+    goto done;
   }
 
   if (authdir_mode_handles_descs(options, -1) &&

Modified: tor/trunk/src/or/dirserv.c
===================================================================
--- tor/trunk/src/or/dirserv.c	2008-09-05 20:18:22 UTC (rev 16778)
+++ tor/trunk/src/or/dirserv.c	2008-09-05 20:52:15 UTC (rev 16779)
@@ -1983,6 +1983,7 @@
     r = tor_snprintf(cp, buf_len - (cp-buf), "p %s\n", summary);
     if (r<0) {
       log_warn(LD_BUG, "Not enough space in buffer.");
+      tor_free(summary);
       return -1;
     }
     cp += strlen(cp);

Modified: tor/trunk/src/or/policies.c
===================================================================
--- tor/trunk/src/or/policies.c	2008-09-05 20:18:22 UTC (rev 16778)
+++ tor/trunk/src/or/policies.c	2008-09-05 20:52:15 UTC (rev 16779)
@@ -1181,15 +1181,15 @@
 cleanup:
   /* cleanup */
   SMARTLIST_FOREACH(summary, policy_summary_item_t *, s, tor_free(s));
-  smartlist_clear(summary);
+  smartlist_free(summary);
 
   tor_free(accepts_str);
   SMARTLIST_FOREACH(accepts, char *, s, tor_free(s));
-  smartlist_clear(accepts);
+  smartlist_free(accepts);
 
   tor_free(rejects_str);
   SMARTLIST_FOREACH(rejects, char *, s, tor_free(s));
-  smartlist_clear(rejects);
+  smartlist_free(rejects);
 
   return result;
 }

Modified: tor/trunk/src/or/rendclient.c
===================================================================
--- tor/trunk/src/or/rendclient.c	2008-09-05 20:18:22 UTC (rev 16778)
+++ tor/trunk/src/or/rendclient.c	2008-09-05 20:52:15 UTC (rev 16779)
@@ -764,13 +764,14 @@
   int res = -1;
   strmap_t *parsed = strmap_new();
   smartlist_t *sl = smartlist_create();
+  rend_service_authorization_t *auth = NULL;
 
   for (line = options->HidServAuth; line; line = line->next) {
     char *onion_address, *descriptor_cookie;
     char descriptor_cookie_tmp[REND_DESC_COOKIE_LEN+2];
     char descriptor_cookie_base64ext[REND_DESC_COOKIE_LEN_BASE64+2+1];
-    rend_service_authorization_t *auth = NULL;
     int auth_type_val = 0;
+    auth = NULL;
     SMARTLIST_FOREACH(sl, char *, c, tor_free(c););
     smartlist_clear(sl);
     smartlist_split_string(sl, line->value, " ",
@@ -829,12 +830,15 @@
       goto err;
     }
     strmap_set(parsed, auth->onion_address, auth);
+    auth = NULL;
   }
   res = 0;
   goto done;
  err:
   res = -1;
  done:
+  if (auth)
+    rend_service_authorization_free(auth);
   SMARTLIST_FOREACH(sl, char *, c, tor_free(c););
   smartlist_free(sl);
   if (!validate_only && res == 0) {

Modified: tor/trunk/src/or/rendcommon.c
===================================================================
--- tor/trunk/src/or/rendcommon.c	2008-09-05 20:18:22 UTC (rev 16778)
+++ tor/trunk/src/or/rendcommon.c	2008-09-05 20:52:15 UTC (rev 16779)
@@ -1064,6 +1064,7 @@
   if (!published && strmap_get_lc(rend_cache, key)) {
     log_info(LD_REND, "We already have a v2 descriptor for service %s.",
              safe_str(query));
+    rend_service_descriptor_free(parsed);
     return -1;
   }
   /* report novel publication to statistics */

Modified: tor/trunk/src/or/rendservice.c
===================================================================
--- tor/trunk/src/or/rendservice.c	2008-09-05 20:18:22 UTC (rev 16778)
+++ tor/trunk/src/or/rendservice.c	2008-09-05 20:52:15 UTC (rev 16779)
@@ -638,6 +638,7 @@
           }
           if (crypto_pk_generate_key(prkey)) {
             log_warn(LD_BUG,"Error generating client key");
+            crypto_free_pk_env(prkey);
             goto err;
           }
           if (crypto_pk_check_key(prkey) <= 0) {
@@ -657,15 +658,17 @@
           goto err;
         }
         if (client->client_key) {
-          char *client_key_out;
+          char *client_key_out = NULL;
           crypto_pk_write_private_key_to_string(client->client_key,
                                                 &client_key_out, &len);
           if (rend_get_service_id(client->client_key, service_id)<0) {
             log_warn(LD_BUG, "Internal error: couldn't encode service ID.");
+            tor_free(client_key_out);
             goto err;
           }
           written = tor_snprintf(buf + written, sizeof(buf) - written,
                                  "client-key\n%s", client_key_out);
+          tor_free(client_key_out);
           if (written < 0) {
             log_warn(LD_BUG, "Could not write client entry.");
             goto err;



More information about the tor-commits mailing list