[or-cvs] stop freeing arbitrary memory
Roger Dingledine
arma at seul.org
Wed Oct 27 12:34:04 UTC 2004
Update of /home2/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv22139
Modified Files:
dirserv.c
Log Message:
stop freeing arbitrary memory
fix a couple of memory leaks
Index: dirserv.c
===================================================================
RCS file: /home2/or/cvsroot/src/or/dirserv.c,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -d -r1.104 -r1.105
--- dirserv.c 27 Oct 2004 06:48:16 -0000 1.104
+++ dirserv.c 27 Oct 2004 12:34:02 -0000 1.105
@@ -799,8 +799,8 @@
/** Replace the current running-routers list with a newly generated one. */
static int generate_runningrouters(crypto_pk_env_t *private_key)
{
- char *s, *cp;
- char *router_status;
+ char *s=NULL, *cp;
+ char *router_status=NULL;
char digest[DIGEST_LEN];
char signature[PK_BYTES];
int i;
@@ -811,8 +811,9 @@
len = 1024+(MAX_HEX_NICKNAME_LEN+2)*smartlist_len(descriptor_list);
s = tor_malloc_zero(len);
- if (list_server_status(NULL, &router_status))
- return -1;
+ if (list_server_status(NULL, &router_status)) {
+ goto err;
+ }
/* ASN.1-encode the public key. This is a temporary measure; once
* everyone is running 0.0.9pre3 or later, we can shift to using a
* PEM-encoded key instead.
@@ -820,14 +821,13 @@
#if 1
if(crypto_pk_DER64_encode_public_key(private_key, &identity_pkey)<0) {
log_fn(LOG_WARN,"write identity_pkey to string failed!");
- tor_free(cp);
- return -1;
+ goto err;
}
#else
{ int l;
if(crypto_pk_write_public_key_to_string(private_key, &identity_pkey, &l)<0){
log_fn(LOG_WARN,"write identity_pkey to string failed!");
- return -1;
+ goto err;
}
}
#endif
@@ -844,21 +844,21 @@
tor_free(identity_pkey);
if (router_get_runningrouters_hash(s,digest)) {
log_fn(LOG_WARN,"couldn't compute digest");
- return -1;
+ goto err;
}
if (crypto_pk_private_sign(private_key, digest, 20, signature) < 0) {
log_fn(LOG_WARN,"couldn't sign digest");
- return -1;
+ goto err;
}
i = strlen(s);
cp = s+i;
if (base64_encode(cp, len-i, signature, 128) < 0) {
log_fn(LOG_WARN,"couldn't base64-encode signature");
- return -1;
+ goto err;
}
if (strlcat(s, "-----END SIGNATURE-----\n", len) >= len) {
- return -1;
+ goto err;
}
tor_free(runningrouters_string);
@@ -866,6 +866,10 @@
runningrouters_len = strlen(s);
runningrouters_is_dirty = 0;
return 0;
+ err:
+ tor_free(s);
+ tor_free(router_status);
+ return -1;
}
/** Set *<b>rr</b> to the most recently generated encoded signed
More information about the tor-commits
mailing list