[aws-cpp-sdk-core] undefined behaviour when flushing ResponseStream before deletion #2319
Labels
bug
This issue is a bug.
p2
This is a standard priority issue
pending-release
This issue will be fixed by an approved PR that hasn't been released yet.
Uh oh!
There was an error while loading. Please reload this page.
Problem description
We encountered segmentation faults after switching from
fstream
to in-memory downloads (stringstream
, boostvectorstream
). It seems the original condition in #58 was not fixed. A related issue (looking at a different aspect) is #1732.In our downloads we set the
rdbuf()
member of theAws::IOStream
(std::iostream
) returned by theResponseStreamFactory
of theGetRequest
, in order to reduce copying.This would not be a problem since the
std::iostream
destructor does not destroy the associatedrdbuf()
.However, the
flush()
operation in~ResponseStream
, which occurs after the download completed, uses the associatedrdbuf()
(which by now has gone out of scope), as shown in the following core dump.Core dump
Analysis
The
GetObjectAsync
call completes in frame 8, whenGetObjectRequestShutdownCallback
calls theGetObjectResponseReceivedHandler
. This is also the time at whichGetObject()
releases the wait semaphore.Some time after the download completed, the
ResponseStream
destructor is called in frame 2, which invokesReleaseStream
in frame 1 withm_underlyingStream->flush()
on ardbuf()
that has already gone out of scope:What to do
Flushing the output may be useful when writing to disk (
fstream
). However, the placement of theflush()
statement is problematic, since it happens after the download completed. In #58, it was already concluded thatflush()
should not happen before deletion, however the associated commit did not touchResponseStream.cpp
.In conclusion, the
flush()
in~ResponseStream
should not happen, since it can not be guaranteed that therdbuf()
of theiostream
is still within scope. There may be other places where such aflush()
is better positioned. A fix is in #2320.AWS CPP SDK version used
1.10.18 (problem also present on
master
).Compiler and Version used
gcc / clang
Operating System and version
Linux, ubuntu 18.04
The text was updated successfully, but these errors were encountered: