Skip to content

provider: free the child libctx on teardown - #519

Merged
yosuke-wolfssl merged 1 commit into
wolfSSL:masterfrom
ColtonWilley:fix/provctx-libctx-leak
Dec 3, 2026
Merged

yosuke-wolfssl merged 1 commit 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.

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

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.
@ColtonWilley
ColtonWilley force-pushed the fix/provctx-libctx-leak branch from 00e7e93 to e509dbb Compare December 2, 2026 22:12
@yosuke-wolfssl yosuke-wolfssl self-assigned this Dec 2, 2026
@yosuke-wolfssl
yosuke-wolfssl self-requested a review December 3, 2026 00:15

@yosuke-wolfssl yosuke-wolfssl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cosmetic: PR body and title don't match to the fix now since it contains CI update only.
I'd merge this but you may update it later.

@yosuke-wolfssl
yosuke-wolfssl merged commit 03f4afd into wolfSSL:master Dec 3, 2026
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:all PR OSP toggle: run all

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants