]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
unit-tests: Free allocated SPIs in mock IPsec backend
authorTobias Brunner <tobias@strongswan.org>
Thu, 15 Oct 2020 16:33:26 +0000 (18:33 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 27 Oct 2020 15:42:01 +0000 (16:42 +0100)
src/libcharon/tests/utils/mock_ipsec.c

index d6172f5bd56068cc87d5547431cc87a58672a4f7..c91bd3683b5a0c88822c0c6b273608f5bb9c7baa 100644 (file)
@@ -224,11 +224,22 @@ METHOD(kernel_ipsec_t, del_policy, status_t,
        return SUCCESS;
 }
 
+CALLBACK(destroy_spis, void,
+       entry_t *entry, const void* key)
+{
+       /* only free allocated SPIs, other SAs that were not properly deleted will
+        * cause a leak */
+       if (entry->alloc)
+       {
+               free(entry);
+       }
+}
+
 METHOD(kernel_ipsec_t, destroy, void,
        private_kernel_ipsec_t *this)
 {
        charon->bus->remove_listener(charon->bus, &this->listener);
-       this->sas->destroy(this->sas);
+       this->sas->destroy_function(this->sas, destroy_spis);
        free(this);
 }