c++ - 使用 AWS Lambda C++ 运行时通过 AWS Lambda 读取 S3 对象时发生内存泄漏
问题描述
我正在使用 AWS Lambda C++ 运行时读取带有 AWS Lambda 的 S3 对象。我使用这个功能:
void s3read(const std::string& bucket, const std::string& key, const std::string& filename_local) {
Aws::Client::ClientConfiguration client_conf;
client_conf.region = Aws::Environment::GetEnv("AWS_REGION");
client_conf.caFile = "/etc/pki/tls/certs/ca-bundle.crt";
Aws::S3::S3Client s3_client(client_conf);
Aws::S3::Model::GetObjectRequest object_request;
object_request.WithBucket(bucket.c_str()).WithKey(key.c_str());
auto get_object_outcome = s3_client.GetObject(object_request);
if(get_object_outcome.IsSuccess()) {
auto &retrieved_file = get_object_outcome.GetResultWithOwnership().GetBody();
Aws::OFStream local_file;
local_file.open(filename_local.c_str(), std::ios::in | std::ios::out | std::ios::binary);
local_file << retrieved_file.rdbuf(); // Leak
local_file.close();
};
std::remove(filename_local.c_str()); // For leak testing purposes
};
它工作正常。但是,如果我反复调用 Lambda, Max Memory Used会不断增长。泄漏似乎来自rdbuf(),但我不知道如何解决它。
更新:当filename_local为/dev/null 时没有泄漏。
解决方案
推荐阅读
- php - 以下日期示例的正确日期格式是什么:“2018-06-06 14:03:57.973468 +00:00”
- python - 如何在ubuntu的vs代码中写python?
- ruby-on-rails - 如何防止 Rails 模型回调中的查询被 id 过滤
- stm32 - -ffunction-sections -fdata-sections 在 keil
- html - Bootstrap 将图标对齐到按钮的左侧
- c# - 如何在运行时更改 LuisService 的 BING SpellCheck?
- r - 包含三个随机数的随机集(在立方体中采样随机点)
- google-app-engine - 两个应用引擎之间的通信:“安全”环境中的灵活和标准
- java - 根据属性类型获取 XmlElement 或 XmlValue
- javascript - HtmlUnit获取编码错误的字符串