Skip to content

DynamoDBClient is there a memory leak? #1953

Closed

Description

@nqf

Describe the bug

==12586== Memcheck, a memory error detector
==12586== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==12586== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==12586== Command: ./cpp-graphql-server --type=2
==12586== Parent PID: 24798
==12586== 
==12586== 
==12586== HEAP SUMMARY:
==12586==     in use at exit: 8,232 bytes in 159 blocks
==12586==   total heap usage: 40,292 allocs, 40,133 frees, 3,774,762 bytes allocated
==12586== 
==12586== 864 (336 direct, 528 indirect) bytes in 2 blocks are definitely lost in loss record 137 of 139
==12586==    at 0x4C2B067: malloc (vg_replace_malloc.c:380)
==12586==    by 0xB8227D: CRYPTO_malloc (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0xB822B0: CRYPTO_zalloc (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0xB7057D: EVP_CIPHER_CTX_new (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0xD963B2: s2n_drbg_instantiate (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0xD910D4: s2n_get_private_random_data (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0xD9112C: s2n_openssl_compat_rand (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0xBA9172: RAND_bytes (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0x6917BA: Aws::Utils::Crypto::SecureRandomBytes_OpenSSLImpl::GetBytes(unsigned char*, unsigned long) (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0x67D610: Aws::Utils::UUID::RandomUUID() (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0x6AE7B7: Aws::Client::AWSClient::AttemptExhaustively(Aws::Http::URI const&, Aws::AmazonWebServiceRequest const&, Aws::Http::HttpMethod, char const*, char const*, char const*) const (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0x6B071B: Aws::Client::AWSJsonClient::MakeRequest(Aws::Http::URI const&, Aws::AmazonWebServiceRequest const&, Aws::Http::HttpMethod, char const*, char const*, char const*) const (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586== 
==12586== 864 (336 direct, 528 indirect) bytes in 2 blocks are definitely lost in loss record 138 of 139
==12586==    at 0x4C2B067: malloc (vg_replace_malloc.c:380)
==12586==    by 0xB8227D: CRYPTO_malloc (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0xB822B0: CRYPTO_zalloc (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0xB7057D: EVP_CIPHER_CTX_new (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0xD963B2: s2n_drbg_instantiate (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0xD910EE: s2n_get_private_random_data (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0xD9112C: s2n_openssl_compat_rand (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0xBA9172: RAND_bytes (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0x6917BA: Aws::Utils::Crypto::SecureRandomBytes_OpenSSLImpl::GetBytes(unsigned char*, unsigned long) (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0x67D610: Aws::Utils::UUID::RandomUUID() (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0x6AE7B7: Aws::Client::AWSClient::AttemptExhaustively(Aws::Http::URI const&, Aws::AmazonWebServiceRequest const&, Aws::Http::HttpMethod, char const*, char const*, char const*) const (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586==    by 0x6B071B: Aws::Client::AWSJsonClient::MakeRequest(Aws::Http::URI const&, Aws::AmazonWebServiceRequest const&, Aws::Http::HttpMethod, char const*, char const*, char const*) const (in /home/fantasy/next/cpp-graphql-server/build/cpp-graphql-server)
==12586== 
==12586== LEAK SUMMARY:
==12586==    definitely lost: 672 bytes in 4 blocks
==12586==    indirectly lost: 1,056 bytes in 4 blocks
==12586==      possibly lost: 0 bytes in 0 blocks
==12586==    still reachable: 6,504 bytes in 151 blocks
==12586==         suppressed: 0 bytes in 0 blocks
==12586== Reachable blocks (those to which a pointer was found) are not shown.
==12586== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==12586== 
==12586== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

Expected Behavior

no memory leak

Current Behavior

memory leak

Reproduction Steps

At present, I put the query operation into the thread, But it seems to have a memory leak

		m_options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info;
		m_options.loggingOptions.logger_create_fn = [] {
			return Aws::MakeShared<Aws::Utils::Logging::ConsoleLogSystem>("console_logger", Aws::Utils::Logging::LogLevel::Info);
		};
		Aws::InitAPI(m_options);
		Aws::Client::ClientConfiguration config;
		config.region = region;
		config.scheme = Aws::Http::Scheme::HTTP;
		config.endpointOverride = endpoint;
		Aws::Auth::AWSCredentials aws_credentials{access_key_id, secret_key};
		m_dynamo_db_client_ptr = std::make_unique<Aws::DynamoDB::DynamoDBClient>(aws_credentials, config);

		std::thread([&] {
			Aws::DynamoDB::Model::ListTablesRequest list_tables_request;
			list_tables_request.SetLimit(50);
			const auto& list_tables_outcome = m_dynamo_db_client_ptr->ListTables(list_tables_request);
		}).detach();
		std::thread([&] {
			Aws::DynamoDB::Model::ListTablesRequest list_tables_request;
			list_tables_request.SetLimit(50);
			const auto& list_tables_outcome = m_dynamo_db_client_ptr->ListTables(list_tables_request);
		}).detach();

Aws::ShutdownAPI(m_options

Possible Solution

No response

Additional Information/Context

No response

AWS CPP SDK version used

the latest version

Compiler and Version used

g++11

Operating System and version

centos7

Activity

  1. added
    bug
    needs-triage
    on Jun 10, 2022
  2. nqf commented on Jun 10, 2022

    @nqf
    Author
  3. jmklix commented on Jun 16, 2022

    @jmklix
    Member

    Looking into the cause of this. As mentioned in the issue you linked it looks like it might be something with when s2n_cleanup is called

  4. added
    investigating
    and removed
    needs-triage
    on Jun 16, 2022
  5. self-assigned this
    on Jun 16, 2022
  6. nqf commented on Jun 16, 2022

    @nqf
    Author

    Looking into the cause of this. As mentioned in the issue you linked it looks like it might be something with when s2n_cleanup is called

    Yes we need to call it,but why not call it in the library

  7. github-actions commented on Jul 17, 2022

    @github-actions

    ⚠️COMMENT VISIBILITY WARNING⚠️

    Comments on closed issues are hard for our team to see.
    If you need more assistance, please either tag a team member or open a new issue that references this one.
    If you wish to keep having a conversation with other community members under this issue feel free to do so.

  8. jmklix commented on May 1, 2023

    @jmklix
    Member

    The source of this has been fixed with this PR. Updating this sdk to version 1.11.62 or greater will remove the need to call s2n_cleanup.

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

Metadata

Metadata

Assignees

Labels

buginvestigating

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions