From 07be14d96b7720dac350b2148dd134514295f990 Mon Sep 17 00:00:00 2001 From: Ava Huang Date: Mon, 1 May 2023 10:14:55 -0700 Subject: [PATCH] Fix some memory leak cases in legacy code --- aws/kinesis/main.cc | 80 +++++++++++++++++++++++--------------------- aws/utils/logging.cc | 4 +++ aws/utils/logging.h | 1 + bootstrap.sh | 2 +- 4 files changed, 48 insertions(+), 39 deletions(-) diff --git a/aws/kinesis/main.cc b/aws/kinesis/main.cc index 1da51e15..9ff30cf1 100644 --- a/aws/kinesis/main.cc +++ b/aws/kinesis/main.cc @@ -361,46 +361,50 @@ int main(int argc, char* const* argv) { aws::utils::setup_aws_logging(options.aws_log_level); Aws::SDKOptions sdk_options; Aws::InitAPI(sdk_options); - - if (options.enable_stack_trace) { - aws::utils::setup_stack_trace(argv[0]); - } - - try { - auto config = get_config(options.configuration); - - if (config->enable_core_dumps()) { - set_core_limit(); + { + if (options.enable_stack_trace) { + aws::utils::setup_stack_trace(argv[0]); } - aws::utils::set_log_level(config->log_level()); - - auto executor = get_executor(); - auto region = get_region(*config); - auto creds_providers = get_creds_providers(); - auto ipc_manager = get_ipc_manager(options.output_pipe, options.input_pipe); - auto ca_path = get_ca_path(); - LOG(info) << "Starting up main producer"; - - aws::kinesis::core::KinesisProducer kp( - ipc_manager, - region, - config, - creds_providers.first, - creds_providers.second, - executor, - ca_path); - - LOG(info) << "Entering join"; - - // Never returns - kp.join(); - } catch (const std::exception& e) { - LOG(error) << e.what(); - return 2; - } catch (int code) { - return code; + try { + auto config = get_config(options.configuration); + + if (config->enable_core_dumps()) { + set_core_limit(); + } + + aws::utils::set_log_level(config->log_level()); + + auto executor = get_executor(); + auto region = get_region(*config); + auto creds_providers = get_creds_providers(); + auto ipc_manager = get_ipc_manager(options.output_pipe, options.input_pipe); + auto ca_path = get_ca_path(); + LOG(info) << "Starting up main producer"; + + aws::kinesis::core::KinesisProducer kp( + ipc_manager, + region, + config, + creds_providers.first, + creds_providers.second, + executor, + ca_path); + + LOG(info) << "Entering join"; + + // Never returns + kp.join(); + } catch (const std::exception& e) { + LOG(error) << e.what(); + return 2; + } catch (int code) { + return code; + } } - + aws::utils::teardown_aws_logging(); + Aws::ShutdownAPI(sdk_options); return 0; } + + diff --git a/aws/utils/logging.cc b/aws/utils/logging.cc index 38701fad..b28ff4ed 100644 --- a/aws/utils/logging.cc +++ b/aws/utils/logging.cc @@ -179,5 +179,9 @@ void setup_aws_logging(Aws::Utils::Logging::LogLevel log_level) { LOG(info) << "Set AWS Log Level to " << Aws::Utils::Logging::GetLogLevelName(log_level); } +void teardown_aws_logging() { + Aws::Utils::Logging::ShutdownAWSLogging(); +} + } //namespace utils } //namespace aws diff --git a/aws/utils/logging.h b/aws/utils/logging.h index e467d471..6398fb44 100644 --- a/aws/utils/logging.h +++ b/aws/utils/logging.h @@ -39,6 +39,7 @@ void setup_logging(const std::string& min_level = "info"); void setup_logging(boost::log::trivial::severity_level level); void setup_aws_logging(Aws::Utils::Logging::LogLevel log_level); +void teardown_aws_logging(); } //namespace utils } //namespace aws diff --git a/bootstrap.sh b/bootstrap.sh index 5f7c02b3..fb989011 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -18,7 +18,7 @@ BOOST_VERSION_UNDERSCORED="${BOOST_VERSION//\./_}" # convert from 1.76.0 to 1_76 ZLIB_VERSION="1.2.13" PROTOBUF_VERSION="3.11.4" CURL_VERSION="7.86.0" -AWS_SDK_CPP_VERSION="1.11.59" +AWS_SDK_CPP_VERSION="1.11.62" LIB_OPENSSL="https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz" LIB_BOOST="https://boostorg.jfrog.io/artifactory/main/release/${BOOST_VERSION}/source/boost_${BOOST_VERSION_UNDERSCORED}.tar.gz"