Creating a copy of the pointer to the underlying data of the stream is not enough to copy the data.
Currently this happens to work sometimes, because the stream may not immediately free unused memory. However, there is no guarantee by the stream interface to always behave this way. Also, if vector::clear
is called on the underlying memory, any pointers to it are invalid.
Fix this, by creating a full copy of all bytes.