[or-cvs] Freeing twice does *not* make the heap twice as clean.

Nick Mathewson nickm at seul.org
Fri Jan 30 21:05:50 UTC 2004


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv19819

Modified Files:
	routerlist.c 
Log Message:
Freeing twice does *not* make the heap twice as clean.

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- routerlist.c	30 Jan 2004 20:59:15 -0000	1.18
+++ routerlist.c	30 Jan 2004 21:05:47 -0000	1.19
@@ -783,6 +783,7 @@
     log_fn(LOG_WARN, "Missing onion key"); goto err;
   } /* XXX Check key length */
   router->onion_pkey = tok->val.public_key;
+  tok->val.public_key = NULL; /* Prevent free */
 
   NEXT_TOKEN();
   if (tok->tp != K_LINK_KEY) {
@@ -793,6 +794,7 @@
     log_fn(LOG_WARN, "Missing link key"); goto err;
   } /* XXX Check key length */
   router->link_pkey = tok->val.public_key;
+  tok->val.public_key = NULL; /* Prevent free */
 
   NEXT_TOKEN();
   if (tok->tp != K_SIGNING_KEY) {
@@ -803,6 +805,7 @@
     log_fn(LOG_WARN, "Missing signing key"); goto err;
   }
   router->identity_pkey = tok->val.public_key;
+  tok->val.public_key = NULL; /* Prevent free */
 
   NEXT_TOKEN();
   while (tok->tp == K_ACCEPT || tok->tp == K_REJECT) {
@@ -1037,10 +1040,12 @@
   switch (tok->tp)
     {
     case _SIGNATURE:
-      free(tok->val.signature);
+      if (tok->val.signature)
+        free(tok->val.signature);
       break;
     case _PUBLIC_KEY:
-      crypto_free_pk_env(tok->val.public_key);
+      if (tok->val.public_key)
+        crypto_free_pk_env(tok->val.public_key);
       break;
     case _ERR:
     case _EOF:



More information about the tor-commits mailing list