Sponsored Content
Skip to content

fix: Fix memory leaks in HTTPClient - #6370

Merged
bthomee merged 14 commits into
developfrom
pratik/-Fix-lsan-issues-in-rippled
Mar 16, 2026
Merged

fix: Fix memory leaks in HTTPClient#6370
bthomee merged 14 commits into
developfrom
pratik/-Fix-lsan-issues-in-rippled

Conversation

@pratikmankawde

@pratikmankawde pratikmankawde commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

High Level Overview of Change

Fix memory leaks in HTTPClient by adding a cleanupSSLContext() method to properly release the global SSL context, and remove the corresponding LSAN suppressions. Refactor the HTTPClient tests to use a Google Test fixture (HTTPClientTest) that manages the SSL context lifecycle via RAII (SetUp/TearDown), making it impossible for tests to leak the context.

Context of Change

The HTTPClient class initializes a global SSL context via initializeSSLContext() but had no way to release it, causing memory leaks flagged by LeakSanitizer. Multiple LSAN suppressions in sanitizers/suppressions/lsan.supp were masking these leaks. The test code also manually called initializeSSLContext() in each test without guaranteed cleanup on failure paths.

This change:

Adds HTTPClient::cleanupSSLContext() which resets the global std::optional.
Removes 11 LSAN suppression entries that are no longer needed.
Refactors tests from free-standing TEST() with manual init/cleanup to a TEST_F() fixture that handles context lifecycle automatically.

Type of Change

[x] Bug fix (non-breaking change which fixes an issue)

Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
@pratikmankawde pratikmankawde added DraftRunCI Normally CI does not run on draft PRs. This opts in. and removed DraftRunCI Normally CI does not run on draft PRs. This opts in. labels Feb 16, 2026
@pratikmankawde
pratikmankawde marked this pull request as ready for review February 16, 2026 15:41
@codecov

codecov Bot commented Feb 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.8%. Comparing base (918185e) to head (73db69e).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #6370     +/-   ##
=========================================
- Coverage     79.9%   79.8%   -0.0%     
=========================================
  Files          878     878             
  Lines        67885   67887      +2     
  Branches      7547    7556      +9     
=========================================
- Hits         54210   54194     -16     
- Misses       13675   13693     +18     
Files with missing lines Coverage Δ
src/libxrpl/net/HTTPClient.cpp 70.9% <100.0%> (+0.3%) ⬆️

... and 6 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Comment thread src/tests/libxrpl/net/HTTPClient.cpp Outdated
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
…ssues-in-rippled

Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
Comment thread src/tests/libxrpl/net/HTTPClient.cpp Outdated
{
break;
}
HTTPClient::initializeSSLContext("", "", false, j_);

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.

nit: Would be great if you added what these params mean (using inline comments)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do, thanks for the quick review :)

@pratikmankawde pratikmankawde removed the DraftRunCI Normally CI does not run on draft PRs. This opts in. label Feb 23, 2026
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
@pratikmankawde pratikmankawde added the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label Feb 23, 2026
@ximinez ximinez added the Needs additional review PR requires at least one more code review approval before it can be merged label Feb 25, 2026
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
@pratikmankawde pratikmankawde removed the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label Feb 25, 2026
@pratikmankawde
pratikmankawde requested a review from a1q123456 March 9, 2026 16:38
@pratikmankawde pratikmankawde changed the title Fix memory leaks in HTTPClient fix: Fix memory leaks in HTTPClient Mar 10, 2026
Comment thread include/xrpl/net/HTTPClient.h
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>

@a1q123456 a1q123456 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.

lgtm.

@pratikmankawde pratikmankawde added Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. and removed Needs additional review PR requires at least one more code review approval before it can be merged labels Mar 16, 2026
@bthomee
bthomee enabled auto-merge (squash) March 16, 2026 14:00
@bthomee
bthomee merged commit b585dc7 into develop Mar 16, 2026
1 check passed
@bthomee
bthomee deleted the pratik/-Fix-lsan-issues-in-rippled branch March 16, 2026 14:12
@mvadari mvadari added this to the 3.2.0 milestone May 20, 2026
beartec-jpg pushed a commit to beartec-jpg/FalconLedger that referenced this pull request Jun 1, 2026
The `HTTPClient` class initializes a global SSL context via `initializeSSLContext()`. However, it had no way to release it, which caused memory leaks flagged by the LeakSanitizer. Multiple LSAN suppressions in the sanitizers' suppressions file were masking these leaks. Our test code also manually called `initializeSSLContext()` in each test without guaranteed cleanup on failure paths.

This change fixes these memory leaks by adding a `cleanupSSLContext()` method to properly release the global SSL context, and removes the corresponding LSAN suppressions. The change further refactors the `HTTPClient` tests to use a Google Test fixture (`HTTPClientTest`) that manages the SSL context lifecycle via RAII (SetUp/TearDown), making it impossible for tests to leak the context.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants