简体   繁体   English

Aws::Delete() 尝试在指向零页的指针上进行 dynamic_cast

[英]Aws::Delete() attempting dynamic_cast on pointer to zero page

I am using the AWS SDK for C++ to access S3 buckets.我正在使用 AWS SDK 为 C++ 访问 S3 存储桶。 This is as part of a larger Unreal Engine project.这是一个更大的虚幻引擎项目的一部分。 As such, the AWS SDK is using the Unreal Engine allocators, hooked in via Aws::Utils::Memory::MemorySystemInterface .因此,AWS SDK 使用虚幻引擎分配器,通过Aws::Utils::Memory::MemorySystemInterface When one of my requests goes out of scope (and is destroyed), I get a segmentation fault in Aws::Delete() .当我的一个请求超出 scope(并被销毁)时,我在Aws::Delete()中遇到分段错误。 This only occurs for a specific GetObject request where i've specified a stream type for the request.这只发生在我为请求指定了 stream 类型的特定GetObject请求中。

The code for the request that breaks is below:中断请求的代码如下:

Aws::S3::Model::GetObjectRequest request;
request.SetBucket(bucket);
request.SetKey(filename);
request.SetResponseStreamFactory([destination_file]() 
{return Aws::New<Aws::FStream>("getdata", destination_file, std::ios_base::out | std::ios_base::binary); }); 
//^ suspect this line to be causing problems, somehow.

Aws::S3::Model::GetObjectOutcome outcome = s3.GetObject(request);
if (!outcome.IsSuccess())
{
    Completed.Broadcast(fullpath, false);
    return;
}
else 
{
    fullpath = to_file;
    Completed.Broadcast(fullpath, true);
    return;
}
//request and outcome leave scope here, triggering an exception.

The request does complete successfully ( outcome.IsSuccess() is true ) and the file appears in the correct place.请求成功完成( outcome.IsSuccess()true )并且文件出现在正确的位置。 Once either outcome or request (i'm not sure which) leaves scope is where it crashes:一旦outcomerequest (我不确定是哪个)离开 scope 就会崩溃:

Exception thrown at 0x00007FFA0CC2612A (vcruntime140.dll) in UnrealEditor.exe: 
0xC0000005: Access violation reading location 0x0000000000000068.

with the following call stack:使用以下调用堆栈:

    vcruntime140.dll!00007ffa0cc2612a() Unknown
    [Inline Frame] aws-cpp-sdk-core.dll!Aws::Delete(std::basic_iostream<char,std::char_traits<char>> * pointerToT) Line 117 C++
    aws-cpp-sdk-core.dll!Aws::Utils::Stream::ResponseStream::ReleaseStream() Line 62    C++
    aws-cpp-sdk-core.dll!Aws::Utils::Stream::ResponseStream::~ResponseStream() Line 54  C++
    UnrealEditor-Plugin.dll!UPlugin::Activate() Line 56 C++

Specifically, the exception is triggered here in AwsMemory.h :具体来说,异常是在AwsMemory.h中触发的:

    template<typename T>
    typename std::enable_if<std::is_polymorphic<T>::value>::type Delete(T* pointerToT)
    {
        if (pointerToT == nullptr)
        {
            return;
        }
        // deal with deleting objects that implement multiple interfaces
        // see casting to pointer to void in http://en.cppreference.com/w/cpp/language/dynamic_cast
        // https://stackoverflow.com/questions/8123776/are-there-practical-uses-for-dynamic-casting-to-void-pointer
        // NOTE: on some compilers, calling the destructor before doing the dynamic_cast affects how calculation of
        // the address of the most derived class.
        void* mostDerivedT = dynamic_cast<void*>(pointerToT); // <-- exception
        pointerToT->~T();
        Free(mostDerivedT);
    }

ReleaseStream() and ResponseStream() seem to just be wrappers for Aws::Delete for this particular instance, the only thing of note being that ReleaseStream flushes the stream before calling Delete . ReleaseStream()ResponseStream()似乎只是这个特定实例的 Aws Aws::Delete的包装器,唯一需要注意的是ReleaseStream在调用Delete之前刷新 stream。 There's nothing that suggests pointerToT should be invalidated before the dynamic_cast , and yet it is.没有任何迹象表明pointerToT应该在dynamic_cast之前失效,但事实确实如此。 This should all be occurring on a single thread.应该都发生在一个线程上。 I have also verified that all the relevant locals (like destination_file ) are valid.我还验证了所有相关的当地人(如destination_file )都是有效的。

What could be causing this behaviour?是什么导致了这种行为? This project has done other requests (List, Put & Get) without issue, although none of them have specified a stream factory.该项目已经完成了其他请求(List、Put & Get)而没有问题,尽管它们都没有指定 stream 工厂。

UE4 is compiled without RTTI, so (obviously) dynamic_cast does not work. UE4 是在没有 RTTI 的情况下编译的,因此(显然) dynamic_cast不起作用。 I believe this was the issue.我相信这就是问题所在。 There is a new problem with calling Delete on polymorphic types without using the dynamic_cast<void*> trick.在不使用dynamic_cast<void*>技巧的情况下对多态类型调用Delete存在一个新问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM