使用aws-sdk-cpp-sqs库时遇到Free()无效指针
Encountered Free() Invalid Pointer when using aws-sdk-cpp-sqs library
我正在尝试使用amazon aws最近为c++发布的实验性sdk。我的目的是让我的c++程序从amazon 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上一样的错误
我手动删除行:add_definitions(-DAWS_CUSTOM_MEMORY_MANAGEMENT)
在CMakeLists.txt文件,重新编译,它工作。
相关文章:
- 如何实现容纳整数和无效指针的双向链表?
- 在基数排序中,我得到 munmap_chunk():无效指针和中止(核心转储).为什么?
- 应用地址清理器后,免费无效指针消失
- C++ 在具有数组成员的类上无效指针/双精度释放
- 不断得到分段错误和free()无效指针
- 使用无效指针初始化指针声明符的行为是否未定义?
- 结构作为参数的函数产生错误:free():无效指针:0x00007efd47b
- 无效指针、隔离标识符等
- c++ 无效指针从空闲列表中取消排队
- C++ munmap_chunk(): 无效指针:
- 为什么我的简单C++程序使用队列和 fstream 错误到无效指针
- 无效指针和非初始化的指针之间的差异
- 如何用无效指针初始化unique_ptr的向量
- 地址清理器在静态强制转换无效指针时报告错误
- MS4:Free(Free()无效指针0xB74E74E0 ***
- ***检测到的GLIBC *** MS2:free():无效指针:0xB7526FF4 ***
- 无效指针功能的输出
- 有人能告诉我这是如何在main()中实现的吗?(关于无效指针的问题)
- C++11使用智能指针,但得到无效指针
- 无效指针的相关性