tls-crypto: Move AEAD ownership to the protection layer
[strongswan.git] / src / libtls / tls_protection.c
index 3d0ec48..2dcca4e 100644 (file)
@@ -123,11 +123,13 @@ METHOD(tls_protection_t, set_cipher, void,
 {
        if (inbound)
        {
 {
        if (inbound)
        {
+               DESTROY_IF(this->aead_in);
                this->aead_in = aead;
                this->seq_in = 0;
        }
        else
        {
                this->aead_in = aead;
                this->seq_in = 0;
        }
        else
        {
+               DESTROY_IF(this->aead_out);
                this->aead_out = aead;
                this->seq_out = 0;
        }
                this->aead_out = aead;
                this->seq_out = 0;
        }
@@ -142,6 +144,8 @@ METHOD(tls_protection_t, set_version, void,
 METHOD(tls_protection_t, destroy, void,
        private_tls_protection_t *this)
 {
 METHOD(tls_protection_t, destroy, void,
        private_tls_protection_t *this)
 {
+       DESTROY_IF(this->aead_in);
+       DESTROY_IF(this->aead_out);
        free(this);
 }
 
        free(this);
 }