c++ - 使用 aws-sdk-cpp-sqs 库时遇到 Free() 无效指针

标签 c++ amazon-web-services sdk amazon-sqs

我正在尝试使用亚马逊AWS最近发布的C++实验性SDK。我的目的是让我的 C++ 程序从亚马逊 SQS 检索消息,因此我需要首先与 SQS 建立连接。我是c++新手。 我成功编译了程序,但在运行时遇到错误

我的代码:

#include <iostream> #include <sstream> #include <iterator> #include <algorithm> #include <string.h> #include <unistd.h> #include <aws/core/client/ClientConfiguration.h> #include <aws/core/client/CoreErrors.h> #include <aws/core/auth/AWSCredentialsProviderChain.h> #include <aws/core/utils/json/JsonSerializer.h> #include <aws/core/utils/xml/XmlSerializer.h> #include <aws/sqs/SQSClient.h> #include <aws/sqs/model/CreateQueueRequest.h> #include <aws/sqs/model/ListQueuesRequest.h> #include <aws/sqs/model/DeleteQueueRequest.h> #include <aws/sqs/model/SendMessageRequest.h> #include <aws/sqs/model/ReceiveMessageRequest.h> #include <aws/sqs/model/DeleteMessageRequest.h> #include <aws/sqs/model/GetQueueAttributesRequest.h> #include <aws/sqs/model/SetQueueAttributesRequest.h> #include <aws/sqs/model/AddPermissionRequest.h> #include <aws/sqs/model/RemovePermissionRequest.h> #include <aws/sqs/model/ListDeadLetterSourceQueuesRequest.h> #include <aws/core/utils/Outcome.h> #include <aws/sqs/model/ChangeMessageVisibilityBatchRequestEntry.h> #include <aws/sqs/model/ChangeMessageVisibilityBatchRequest.h> #include <aws/sqs/model/SendMessageBatchRequestEntry.h> #include <aws/sqs/model/SendMessageBatchRequest.h> #include <memory> using namespace Aws::Http; using namespace Aws; using namespace Aws::Auth; using namespace Aws::Client; using namespace Aws::SQS; using namespace Aws::SQS::Model; using namespace Aws::Utils::Json; 
int main(int argc, char** argv) { 
//Initialize SQS client 
ClientConfiguration config; 
config.scheme = Scheme::HTTPS; 
config.region = Aws::Region::US_EAST_1; std::unique_ptr<SQSClient> sqsClient(new SQSClient(config)); return 0; } 

报告错误:free() 无效指针 0x00007f5a80eeaa80


来自 valgrind 的快照日志:

1 errors in context 10 of 10: ==22040== Invalid free() / delete / delete[] / realloc() ==22040== at 0x4C2C2BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==22040== by 0x5A001BF: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21) ==22040== by 0x40154D: Aws::Client::ClientConfiguration::~ClientConfiguration() (ClientConfiguration.h:53) ==22040== by 0x56D730A: Aws::Internal::EC2MetadataClient::EC2MetadataClient(char const*, std::shared_ptr<Aws::Http::HttpClientFactory const>) (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== by 0x56C8541: _ZN9__gnu_cxx13new_allocatorIN3Aws8Internal17EC2MetadataClientEE9constructIS3_IEEEvPT_DpOT0_ (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== by 0x56C8406: _ZNSt16allocator_traitsIN3Aws9AllocatorINS0_8Internal17EC2MetadataClientEEEE12_S_constructIS3_IEEENSt9enable_ifIXsrNS5_18__construct_helperIT_IDpT0_EEE5valueEvE4typeERS4_PS9_DpOSA_ (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== by 0x56C8308: _ZNSt16allocator_traitsIN3Aws9AllocatorINS0_8Internal17EC2MetadataClientEEEE9constructIS3_IEEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS4_PT_DpOS7_ (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== by 0x56C8110: std::_Sp_counted_ptr_inplace<Aws::Internal::EC2MetadataClient, Aws::Allocator<Aws::Internal::EC2MetadataClient>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<>(Aws::Allocator<Aws::Internal::EC2MetadataClient>) (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== by 0x56C7DFD: _ZN9__gnu_cxx13new_allocatorISt23_Sp_counted_ptr_inplaceIN3Aws8Internal17EC2MetadataClientENS2_9AllocatorIS4_EELNS_12_Lock_policyE2EEE9constructIS8_IKS6_EEEvPT_DpOT0_ (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== by 0x56C7C00: _ZNSt16allocator_traitsIN3Aws9AllocatorISt23_Sp_counted_ptr_inplaceINS0_8Internal17EC2MetadataClientENS1_IS4_EELN9__gnu_cxx12_Lock_policyE2EEEEE12_S_constructIS8_IKS5_EEENSt9enable_ifIXsrNSA_18__construct_helperIT_IDpT0_EEE5valueEvE4typeERS9_PSF_DpOSG_ (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== by 0x56C7903: _ZNSt16allocator_traitsIN3Aws9AllocatorISt23_Sp_counted_ptr_inplaceINS0_8Internal17EC2MetadataClientENS1_IS4_EELN9__gnu_cxx12_Lock_policyE2EEEEE9constructIS8_IKS5_EEEDTcl12_S_constructfp_fp0_spcl7forwardIT0_Efp1_EEERS9_PT_DpOSD_ (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== by 0x56C75F8: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<Aws::Internal::EC2MetadataClient, Aws::Allocator<Aws::Internal::EC2MetadataClient>>(std::_Sp_make_shared_tag, Aws::Internal::EC2MetadataClient*, Aws::Allocator<Aws::Internal::EC2MetadataClient> const&) (in /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-core.so) ==22040== Address 0x55a3680 is in the BSS segment of /usr/lib/x86_64-linux-gnu/libaws-cpp-sdk-sqs.so ==22040== ==22040== ERROR SUMMARY: 10 errors from 10 contexts (suppressed: 0 from 0) 

最佳答案

我认为该问题与 AWS C++ SDK 中内置的 AWS 自定义内存管理支持有关。默认情况下,如果您针对共享库进行编译,AWS 会打开自定义内存管理。这在 osx 上运行良好,但我在 ubuntu 14.04 上收到了与您相同的错误

我手动删除了 CMakeLists.txt 文件中的行:add_definitions(-DAWS_CUSTOM_MEMORY_MANAGEMENT),重新编译后即可正常工作。

关于c++ - 使用 aws-sdk-cpp-sqs 库时遇到 Free() 无效指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32961616/

相关文章:

c++ - 如果在构造函数中引发异常会发生什么

c++ - 测验;这会编译吗?如果是,它会返回什么(我知道答案)

ios - 使用适用于 iOS 的 AWS S3 SDK v2 上传图像 : Track progress

amazon-web-services - 弹性负载均衡器返回空回复

java - 502 错误网关 Elastic Beanstalk Spring Boot

java - 安卓服务器: Parse server gradle build

visual-c++ - 适用于 Windows 8.1 的 Windows SDK 包括哪些内容?

c++ - 为什么全局数组在只读模式下不消耗内存?

ios - 如何在iPhone中的UIScrollView中动态添加图像

c++ - 如何使用 googletest 捕获标准输出/标准错误?