2015-10-06 54 views
2

我想使用最近由amazon aws for C++發佈的實驗性sdk。我的目的是讓我的C++程序從amazon SQS中檢索消息,因此我需要先與SQS建立連接。我是新的C++。 我設法編譯程序,但運行時遇到免費()使用aws-sdk-cpp-sqs庫時無效指針

我的代碼過程中遇到的錯誤:

#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; } 

報告錯誤:免費()無效指針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) 

回答

1

我認爲這個問題與AWS C++ SDK中內置的AWS自定義內存管理支持有關。默認情況下,如果您編譯共享庫,AWS將打開自定義內存管理。這在osx上工作正常,但我收到了與你在Ubuntu 14.04

相同的錯誤我手動刪除CMakeLists.txt文件中的行:add_definitions(-DAWS_CUSTOM_MEMORY_MANAGEMENT),重新編譯,它的工作。

+0

我調用'cmake ..'時已經用'-DCUSTOM_MEMORY_MANAGEMENT = 0'標誌安裝了它,它也可以工作(所以+1) – sop