Skip to content

provider: free the child libctx on teardown - #519

Open
ColtonWilley wants to merge 2 commits into
wolfSSL:masterfrom
ColtonWilley:fix/provctx-libctx-leak
Open

ColtonWilley wants to merge 2 commits into
wolfSSL:masterfrom
ColtonWilley:fix/provctx-libctx-leak

Conversation

@ColtonWilley

Copy link
Copy Markdown
Contributor

wolfssl_provider_init creates a child library context with OSSL_LIB_CTX_new_child() that the provider owns, but teardown never freed it: ~37 KB leaks per explicitly loaded or config-activated instance, growing in apps that repeatedly create a libctx and load a provider (e.g. OpenSC in replace-default mode). It is now freed first in teardown, as OpenSSL's legacy provider does. The ASan unit-test step now runs with leak detection, which fails on master.

wolfssl_provider_init creates a child library context with
OSSL_LIB_CTX_new_child() that the provider owns, but teardown never freed
it, leaking ~37 KB per explicitly loaded or config-activated instance.
Free it first in teardown, as OpenSSL's legacy provider does.
The test binaries link libasan, so drop the preload after env-setup and
run make test with detect_leaks=1. make and the shell tools stay
unchecked.
Copilot AI balanced review requested due to automatic review settings October 27, 2026 00:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused cleanup matches context ownership, the sanitizer changes align with test linking, and no blocking issues remain.

No open issues 🎉

What changed in this PR

Fixes a provider-instance memory leak by freeing the owned child OpenSSL library context during teardown, and enables leak detection for sanitizer unit tests.

Changes:

  • Free the child library context before other provider resources.
  • Clarify library-context ownership in internal comments.
  • Enable LeakSanitizer for make test and update sanitizer documentation.
File Description
src/​wp_wolfprov.c Free the child context during teardown and clarify ownership.
include/​wolfprovider/​internal.h Document that the library context is owned and nullable.
.github/​workflows/​sanitizers.yml Enable unit-test leak detection without preloading the sanitizer runtime.
.github/​workflows/​README.md Document leak checks and sanitizer runtime loading.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants