From 610745e72491ca0a6833db6b9d5e34bb8596e374 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 15 Oct 2020 18:33:26 +0200 Subject: [PATCH] unit-tests: Free allocated SPIs in mock IPsec backend --- src/libcharon/tests/utils/mock_ipsec.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libcharon/tests/utils/mock_ipsec.c b/src/libcharon/tests/utils/mock_ipsec.c index d6172f5bd5..c91bd3683b 100644 --- a/src/libcharon/tests/utils/mock_ipsec.c +++ b/src/libcharon/tests/utils/mock_ipsec.c @@ -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); } -- 2.47.2