From ee53c3924fcc449a581380a1283a8652aa15652c Mon Sep 17 00:00:00 2001 From: Clemens Lang Date: Fri, 22 Nov 2024 11:29:29 +0100 Subject: [PATCH] Fix memory leak of ctx_pool.contexts Related: https://bugzilla.redhat.com/show_bug.cgi?id=2327985 Signed-off-by: Clemens Lang --- src/provider.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/provider.c b/src/provider.c index 199659c9..1d4495e5 100644 --- a/src/provider.c +++ b/src/provider.c @@ -219,6 +219,12 @@ static void context_rm_pool(struct p11prov_ctx *ctx) } if (found) { ctx_pool.num--; + if (ctx_pool.num == 0) { + /* This was the last context, free ctx_pool.contexts to avoid + * leaking memory. */ + OPENSSL_free(ctx_pool.contexts); + ctx_pool.contexts = NULL; + } } else { P11PROV_debug("Context not found in pool ?!"); }