]> git.meshlink.io Git - meshlink/commitdiff
Fix memory leaks found by valgrind.
authorGuus Sliepen <guus@tinc-vpn.org>
Tue, 9 Oct 2012 14:27:28 +0000 (16:27 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Tue, 9 Oct 2012 14:27:28 +0000 (16:27 +0200)
src/net_setup.c
src/net_socket.c
src/openssl/cipher.c
src/openssl/digest.c
src/protocol_key.c
src/sptps.c

index 5d4e9157cefdc1df31b76f2b869f1c2ae162ae78..00273cfe1007f2e3b0a64c4c2c2e0f246c898498 100644 (file)
@@ -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)) {
index df6f3c048e78d81e00ed93f2d62627e44ee650c2..36da2d0dd10588eb6c4642a486ce729d316f5c54 100644 (file)
@@ -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);
 
index 1ca15abb1817693f9a37b73946f116bd9e90f94d..abd652c443121ec184208f18cc9ab10eed1df803 100644 (file)
@@ -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) {
index 3159e7a39a90fa9388927f675a9ad020b8a9fe75..e88274e69bdb1512b6fee018e682955ca347705d 100644 (file)
@@ -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;
 }
 
index fb53fe141927322e3ce2a706540e8ef7497d8315..c042c4b5e259f5dc2c463aa9a2654875499dbc47 100644 (file)
@@ -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) {
index 10d6e047f78f5d02c52087c354dad710fe05160a..ed1d952bbb48f94ab542f57dc5f44671084bd5d2 100644 (file)
@@ -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;
 }