Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3Client Leaks Memory on Windows caused by BCrypt API Misuse #2918

Closed
normanade opened this issue Apr 11, 2024 · 3 comments
Closed

S3Client Leaks Memory on Windows caused by BCrypt API Misuse #2918

normanade opened this issue Apr 11, 2024 · 3 comments
Labels
bug This issue is a bug. p2 This is a standard priority issue pending-release This issue will be fixed by an approved PR that hasn't been released yet.

Comments

@normanade
Copy link
Contributor

Describe the bug

Aws::S3::S3Client leaks memory on Windows, when uses windows api BCrypt. Aws::Utils::Crypto::BCryptHashImpl, which is used by the default signer Aws::Auth::AWSAuthV4Signer on windows (when AWS_LC cmake option OFF), failed to deconstruct correctly, and leaks memory by 2800KiB per 1k construction & deconstruction call pairs.

Expected Behavior

Aws::S3::S3Client should construct and deconstruct without memory leak.

Current Behavior

Per 1k call pair of Aws::S3::S3Client construction & deconstruction, the whole program leaks about 2800KiB memory. Using Visual Studio's heap analyzer, difference of heap snapshot between the beginning and the ending of the program shows that certain parts of Aws::Utils::Crypto::BCryptHashImpl stays unreleased.
aws1
aws2

Reproduction Steps

// loop for 1000 times
Aws::Client::ClientConfigurationInitValues s3ConfigInitValues;
s3ConfigInitValues.shouldDisableIMDS = true;
Aws::Client::ClientConfiguration s3ClientConfig(s3ConfigInitValues);

s3ClientConfig.endpointOverride = "127.0.0.1:8443";
s3ClientConfig.verifySSL = false;
s3ClientConfig.scheme = Aws::Http::Scheme::HTTPS;
s3ClientConfig.requestTimeoutMs = 3000;

std::shared_ptr<Aws::Auth::SimpleAWSCredentialsProvider> p_s3Cred = std::make_shared<Aws::Auth::SimpleAWSCredentialsProvider>
	("ak", "sk");
std::shared_ptr<Aws::S3::Endpoint::S3EndpointProvider> p_s3End = std::make_shared<Aws::S3::Endpoint::S3EndpointProvider>();
Aws::S3::S3Client* pClient = new Aws::S3::S3Client(p_s3Cred, p_s3End, s3ClientConfig);
delete pClient;

Possible Solution

Aws::Utils::Crypto::BCryptHashImpl & Aws::Utils::Crypto::BCryptHashContext didn't deconstruct correctly. Deconstruct all the member variables should fix the problem.

Additional Information/Context

No response

AWS CPP SDK version used

1.11.290

Compiler and Version used

Visual Studio 2022

Operating System and version

Windows 10

@normanade normanade added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 11, 2024
@jmklix
Copy link
Member

jmklix commented Apr 11, 2024

Thanks for finding this and opening a PR to fix it. Reviewing and testing your PR.

@jmklix jmklix added pending-release This issue will be fixed by an approved PR that hasn't been released yet. p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Apr 11, 2024
@DmitriyMusatkin
Copy link
Contributor

PR has been merged.

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p2 This is a standard priority issue pending-release This issue will be fixed by an approved PR that hasn't been released yet.
Projects
None yet
Development

No branches or pull requests

3 participants