void AutoChildOpArgs::Add(JSContext* aCx, InternalRequest* aRequest, BodyAction aBodyAction, SchemeAction aSchemeAction, Response& aResponse, ErrorResult& aRv) { MOZ_DIAGNOSTIC_ASSERT(!mSent); switch(mOpArgs.type()) { case CacheOpArgs::TCachePutAllArgs: { CachePutAllArgs& args = mOpArgs.get_CachePutAllArgs(); // Throw an error if a request/response pair would mask another // request/response pair in the same PutAll operation. This is // step 2.3.2.3 from the "Batch Cache Operations" spec algorithm. if (MatchInPutList(aRequest, args.requestResponseList())) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } // Ensure that we don't realloc the array since this can result // in our AutoIPCStream objects to reference the wrong memory // location. This should never happen and is a UAF if it does. // Therefore make this a release assertion. MOZ_RELEASE_ASSERT(args.requestResponseList().Length() < args.requestResponseList().Capacity()); // The FileDescriptorSetChild asserts in its destructor that all fds have // been removed. The copy constructor, however, simply duplicates the // fds without removing any. This means each temporary and copy must be // explicitly cleaned up. // // Avoid a lot of this hassle by making sure we only create one here. On // error we remove it. CacheRequestResponse& pair = *args.requestResponseList().AppendElement(); pair.request().body() = void_t(); pair.response().body() = void_t(); mTypeUtils->ToCacheRequest(pair.request(), aRequest, aBodyAction, aSchemeAction, mStreamCleanupList, aRv); if (!aRv.Failed()) { mTypeUtils->ToCacheResponse(aCx, pair.response(), aResponse, mStreamCleanupList, aRv); } if (aRv.Failed()) { CleanupChild(pair.request().body(), Delete); args.requestResponseList().RemoveElementAt( args.requestResponseList().Length() - 1); } break; } default: MOZ_CRASH("Cache args type cannot send a Request/Response pair!"); } }
AutoChildOpArgs::~AutoChildOpArgs() { CleanupAction action = mSent ? Forget : Delete; switch(mOpArgs.type()) { case CacheOpArgs::TCacheMatchArgs: { CacheMatchArgs& args = mOpArgs.get_CacheMatchArgs(); CleanupChild(args.request().body(), action); break; } case CacheOpArgs::TCacheMatchAllArgs: { CacheMatchAllArgs& args = mOpArgs.get_CacheMatchAllArgs(); if (args.requestOrVoid().type() == CacheRequestOrVoid::Tvoid_t) { break; } CleanupChild(args.requestOrVoid().get_CacheRequest().body(), action); break; } case CacheOpArgs::TCachePutAllArgs: { CachePutAllArgs& args = mOpArgs.get_CachePutAllArgs(); auto& list = args.requestResponseList(); for (uint32_t i = 0; i < list.Length(); ++i) { CleanupChild(list[i].request().body(), action); CleanupChild(list[i].response().body(), action); } break; } case CacheOpArgs::TCacheDeleteArgs: { CacheDeleteArgs& args = mOpArgs.get_CacheDeleteArgs(); CleanupChild(args.request().body(), action); break; } case CacheOpArgs::TCacheKeysArgs: { CacheKeysArgs& args = mOpArgs.get_CacheKeysArgs(); if (args.requestOrVoid().type() == CacheRequestOrVoid::Tvoid_t) { break; } CleanupChild(args.requestOrVoid().get_CacheRequest().body(), action); break; } case CacheOpArgs::TStorageMatchArgs: { StorageMatchArgs& args = mOpArgs.get_StorageMatchArgs(); CleanupChild(args.request().body(), action); break; } default: // Other types do not need cleanup break; } mStreamCleanupList.Clear(); }
void CStreamVideoSource::Stop() { if( m_bRun ) { m_bRun = FALSE; // Wait for stop ASSERT( WaitForSingleObject( m_hThreadEndEvent, 10000 ) == WAIT_OBJECT_0 ); if( m_piStreamer.hProcess ) { TerminateProcess( m_piStreamer.hProcess, 0 ); CleanupChild(); } } }
BOOL CStreamVideoSource::GetRawImage(BYTE **pRawData, FILETIME *timestamp, DWORD *bEOF ) { // Lock the image here and don't unlock until we get the frame back EnterCriticalSection(&m_csBufLock); *bEOF = FALSE; if( m_bGotVideoFrame ) { // Get the next frame *pRawData = m_pAlignedImg; // Need Time stamp GetSystemTimeAsFileTime(timestamp); FileTimeToLocalFileTime(timestamp, timestamp); m_bGotVideoFrame = FALSE; return TRUE; } else { // Nothing.. unlock LeaveCriticalSection(&m_csBufLock); // Check for process exit if( WAIT_OBJECT_0 == WaitForSingleObject( m_piStreamer.hProcess, 0 ) ) { // Child process has disappeared (exited) *bEOF = TRUE; m_bRun = FALSE; CleanupChild(); } return FALSE; } }