Fix memory leaks found by valgrind.
This commit is contained in:
parent
72642b40b3
commit
d1ec010660
6 changed files with 20 additions and 12 deletions
|
@ -680,6 +680,8 @@ static bool setup_myself(void) {
|
|||
return false;
|
||||
}
|
||||
|
||||
free(cipher);
|
||||
|
||||
regenerate_key();
|
||||
|
||||
/* Check if we want to use message authentication codes... */
|
||||
|
@ -700,6 +702,8 @@ static bool setup_myself(void) {
|
|||
return false;
|
||||
}
|
||||
|
||||
free(digest);
|
||||
|
||||
/* Compression */
|
||||
|
||||
if(get_config_int(lookup_config(config_tree, "Compression"), &myself->incompression)) {
|
||||
|
|
|
@ -571,6 +571,9 @@ static void free_outgoing(outgoing_t *outgoing) {
|
|||
if(outgoing->ai)
|
||||
freeaddrinfo(outgoing->ai);
|
||||
|
||||
if(outgoing->config_tree)
|
||||
exit_configuration(&outgoing->config_tree);
|
||||
|
||||
if(outgoing->name)
|
||||
free(outgoing->name);
|
||||
|
||||
|
|
|
@ -65,10 +65,8 @@ bool cipher_open_blowfish_ofb(cipher_t *cipher) {
|
|||
|
||||
void cipher_close(cipher_t *cipher) {
|
||||
EVP_CIPHER_CTX_cleanup(&cipher->ctx);
|
||||
if(cipher->counter) {
|
||||
free(cipher->counter);
|
||||
cipher->counter = 0;
|
||||
}
|
||||
free(cipher->counter);
|
||||
cipher->counter = NULL;
|
||||
}
|
||||
|
||||
size_t cipher_keylength(const cipher_t *cipher) {
|
||||
|
|
|
@ -78,8 +78,7 @@ bool digest_set_key(digest_t *digest, const void *key, size_t len) {
|
|||
}
|
||||
|
||||
void digest_close(digest_t *digest) {
|
||||
if(digest->key)
|
||||
free(digest->key);
|
||||
free(digest->key);
|
||||
digest->key = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -258,6 +258,9 @@ bool send_ans_key(node_t *to) {
|
|||
size_t keylen = cipher_keylength(&myself->incipher);
|
||||
char key[keylen * 2 + 1];
|
||||
|
||||
cipher_close(&to->incipher);
|
||||
digest_close(&to->indigest);
|
||||
|
||||
cipher_open_by_nid(&to->incipher, cipher_get_nid(&myself->incipher));
|
||||
digest_open_by_nid(&to->indigest, digest_get_nid(&myself->indigest), digest_length(&myself->indigest));
|
||||
to->incompression = myself->incompression;
|
||||
|
@ -345,6 +348,8 @@ bool ans_key_h(connection_t *c, const char *request) {
|
|||
}
|
||||
|
||||
/* Don't use key material until every check has passed. */
|
||||
cipher_close(&from->outcipher);
|
||||
digest_close(&from->outdigest);
|
||||
from->status.validkey = false;
|
||||
|
||||
if(compression < 0 || compression > 11) {
|
||||
|
|
11
src/sptps.c
11
src/sptps.c
|
@ -627,18 +627,17 @@ bool sptps_start(sptps_t *s, void *handle, bool initiator, bool datagram, ecdsa_
|
|||
// Stop a SPTPS session.
|
||||
bool sptps_stop(sptps_t *s) {
|
||||
// Clean up any resources.
|
||||
cipher_close(&s->incipher);
|
||||
cipher_close(&s->outcipher);
|
||||
digest_close(&s->indigest);
|
||||
digest_close(&s->outdigest);
|
||||
ecdh_free(&s->ecdh);
|
||||
free(s->inbuf);
|
||||
s->inbuf = NULL;
|
||||
free(s->mykex);
|
||||
s->mykex = NULL;
|
||||
free(s->hiskex);
|
||||
s->hiskex = NULL;
|
||||
free(s->key);
|
||||
s->key = NULL;
|
||||
free(s->label);
|
||||
s->label = NULL;
|
||||
free(s->late);
|
||||
s->late = NULL;
|
||||
memset(s, 0, sizeof *s);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue