From 07989cde5b8797e8ea43b7fb153eeef1d8a21f33 Mon Sep 17 00:00:00 2001 From: hunjmes <106619278+hunjmes@users.noreply.github.com> Date: Mon, 10 Jul 2023 18:41:13 -0700 Subject: [PATCH 1/4] Fix issue 2568 A recent change caused redundant calls to Aws::ShutdownAPI() to crash, with SEGV, due to null pointer dereference. This commit fixes this regression and adds a unit test that shows that calling Aws::ShutdownAPI() multiple times no longer crashes. --- .../AwsSdkMisuseTests.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/aws-cpp-sdk-eventbridge-tests/AwsSdkMisuseTests.cpp b/tests/aws-cpp-sdk-eventbridge-tests/AwsSdkMisuseTests.cpp index 1c8f58c1437..9362eacbf8a 100644 --- a/tests/aws-cpp-sdk-eventbridge-tests/AwsSdkMisuseTests.cpp +++ b/tests/aws-cpp-sdk-eventbridge-tests/AwsSdkMisuseTests.cpp @@ -108,3 +108,18 @@ TEST_F(AwsSdkMisuseTest, MissingCurlyBracesTest) ASSERT_FALSE(outcomeAfterShutdown.IsSuccess()); ASSERT_EQ((Aws::Client::CoreErrors) outcomeAfterShutdown.GetError().GetErrorType(), Aws::Client::CoreErrors::NOT_INITIALIZED); } + +TEST_F(AwsSdkMisuseTest, MultipleShutdownTest) +{ + Aws::SDKOptions options; + options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace; + + Aws::InitAPI(options); + + // Shutdown the API. + Aws::ShutdownAPI(options); + // Now shut it down a second time. (This call must not crash.) + Aws::ShutdownAPI(options); + // And one more time, for good measure. + Aws::ShutdownAPI(options); +} From 2d33530c5a533516b5aa1ef693048b62c1baa628 Mon Sep 17 00:00:00 2001 From: hunjmes <106619278+hunjmes@users.noreply.github.com> Date: Mon, 10 Jul 2023 20:18:38 -0700 Subject: [PATCH 2/4] Update AwsSdkMisuseTests.cpp From ef924118ac6899f67aaecbc09329f87aaca3dc0a Mon Sep 17 00:00:00 2001 From: hunjmes <106619278+hunjmes@users.noreply.github.com> Date: Mon, 10 Jul 2023 20:19:54 -0700 Subject: [PATCH 3/4] Update Globals.cpp --- src/aws-cpp-sdk-core/source/Globals.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/aws-cpp-sdk-core/source/Globals.cpp b/src/aws-cpp-sdk-core/source/Globals.cpp index 8c26d2389dd..36342a23c32 100644 --- a/src/aws-cpp-sdk-core/source/Globals.cpp +++ b/src/aws-cpp-sdk-core/source/Globals.cpp @@ -72,5 +72,6 @@ namespace Aws void CleanupEnumOverflowContainer() { Aws::Delete(g_enumOverflow); + g_enumOverflow = nullptr; } } From 88d73fb15f970a5c94329e7a3f8b4b14c516e915 Mon Sep 17 00:00:00 2001 From: hunjmes <106619278+hunjmes@users.noreply.github.com> Date: Mon, 10 Jul 2023 20:21:05 -0700 Subject: [PATCH 4/4] Update ComponentRegistry.cpp --- .../utils/component-registry/ComponentRegistry.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/aws-cpp-sdk-core/source/utils/component-registry/ComponentRegistry.cpp b/src/aws-cpp-sdk-core/source/utils/component-registry/ComponentRegistry.cpp index 95625c73910..4795650cae8 100644 --- a/src/aws-cpp-sdk-core/source/utils/component-registry/ComponentRegistry.cpp +++ b/src/aws-cpp-sdk-core/source/utils/component-registry/ComponentRegistry.cpp @@ -42,7 +42,6 @@ namespace Aws void ShutdownComponentRegistry() { std::unique_lock lock(s_registryMutex); - assert(s_registry); Aws::Delete(s_registry); s_registry = nullptr; @@ -80,7 +79,11 @@ namespace Aws void TerminateAllComponents() { std::unique_lock lock(s_registryMutex); - assert(s_registry); + + if (!s_registry) { + // Registry already shut down -- nothing to do. + return; + } for(const auto it : *s_registry) { @@ -93,4 +96,4 @@ namespace Aws } // namespace ComponentRegistry } // namespace Utils -} // namespace Aws \ No newline at end of file +} // namespace Aws