[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Fix some memory leaks and unlikely segfaults
Update of /home/or/cvsroot/tor/src/common
In directory moria.mit.edu:/tmp/cvs-serv31936/src/common
Modified Files:
tortls.c
Log Message:
Fix some memory leaks and unlikely segfaults
Index: tortls.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/tortls.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- tortls.c 7 Dec 2004 06:48:02 -0000 1.81
+++ tortls.c 7 Dec 2004 07:47:57 -0000 1.82
@@ -338,8 +338,11 @@
if (!client_only) {
if (cert && !SSL_CTX_use_certificate(*ctx,cert))
goto error;
+ X509_free(cert); /* We just added a reference to cert. */
+ cert=NULL;
if (idcert && !SSL_CTX_add_extra_chain_cert(*ctx,idcert))
goto error;
+ idcert=NULL; /* The context now owns the reference to idcert */
}
SSL_CTX_set_session_cache_mode(*ctx, SSL_SESS_CACHE_OFF);
if (isServer && !client_only) {
@@ -350,10 +353,8 @@
goto error;
EVP_PKEY_free(pkey);
pkey = NULL;
- if (cert) {
- if (!SSL_CTX_check_private_key(*ctx))
- goto error;
- }
+ if (!SSL_CTX_check_private_key(*ctx))
+ goto error;
}
dh = crypto_dh_new();
SSL_CTX_set_tmp_dh(*ctx, _crypto_dh_env_get_dh(dh));
@@ -393,7 +394,7 @@
if (cert)
X509_free(cert);
if (idcert)
- X509_free(cert);
+ X509_free(idcert);
return -1;
}
@@ -614,12 +615,12 @@
log_fn(LOG_WARN, "Peer certificate nickname has illegal characters.");
goto error;
}
+ X509_free(cert);
+
return 0;
error:
if (cert)
X509_free(cert);
- if (name)
- X509_NAME_free(name);
return -1;
}