Bug 1398635 - IPCBlobInputStream must release the remoteStream when the pipe inputStream wraps it in order to avoid double close(), r=smaug

This commit is contained in:
Andrea Marchesini 2017-09-11 13:08:36 +02:00
parent 8aa3f52fda
commit 683768374b

View File

@ -156,7 +156,7 @@ IPCBlobInputStream::Available(uint64_t* aLength)
}
if (mState == eRunning) {
MOZ_ASSERT(mRemoteStream);
MOZ_ASSERT(mRemoteStream || mAsyncRemoteStream);
// This will go away eventually: an async input stream can return 0 in
// Available(), but this is not currently fully supported in the rest of
@ -188,7 +188,7 @@ IPCBlobInputStream::Read(char* aBuffer, uint32_t aCount, uint32_t* aReadCount)
}
if (mState == eRunning) {
MOZ_ASSERT(mRemoteStream);
MOZ_ASSERT(mRemoteStream || mAsyncRemoteStream);
nsresult rv = EnsureAsyncRemoteStream();
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -213,7 +213,7 @@ IPCBlobInputStream::ReadSegments(nsWriteSegmentFun aWriter, void* aClosure,
}
if (mState == eRunning) {
MOZ_ASSERT(mRemoteStream);
MOZ_ASSERT(mRemoteStream || mAsyncRemoteStream);
nsresult rv = EnsureAsyncRemoteStream();
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -391,7 +391,7 @@ IPCBlobInputStream::MaybeExecuteInputStreamCallback(nsIInputStreamCallback* aCal
nsIEventTarget* aCallbackEventTarget)
{
MOZ_ASSERT(mState == eRunning);
MOZ_ASSERT(mRemoteStream);
MOZ_ASSERT(mRemoteStream || mAsyncRemoteStream);
// If the callback has been already set, we return an error.
if (mInputStreamCallback && aCallback) {
@ -549,15 +549,15 @@ IPCBlobInputStream::GetFileDescriptor(PRFileDesc** aRetval)
nsresult
IPCBlobInputStream::EnsureAsyncRemoteStream()
{
if (!mRemoteStream) {
return NS_ERROR_FAILURE;
}
// We already have an async remote stream.
if (mAsyncRemoteStream) {
return NS_OK;
}
if (!mRemoteStream) {
return NS_ERROR_FAILURE;
}
// If the stream is blocking, we want to make it unblocking using a pipe.
bool nonBlocking = false;
nsresult rv = mRemoteStream->IsNonBlocking(&nonBlocking);
@ -597,6 +597,7 @@ IPCBlobInputStream::EnsureAsyncRemoteStream()
MOZ_ASSERT(asyncStream);
mAsyncRemoteStream = asyncStream;
mRemoteStream = nullptr;
return NS_OK;