Bug 1349746 - Ensure we close media cache's temporary file if the cache shuts down while we're waiting for the FD to arrive. r?jwwang
In some situations the MediaCache can be shutdown while we're waiting for the
parent process to return a temporary file. We should close the temporary file
so that we don't leak it in this situation.
MozReview-Commit-ID: E3pgO8nWDB8
--- a/dom/media/FileBlockCache.cpp
+++ b/dom/media/FileBlockCache.cpp
@@ -20,16 +20,27 @@ LazyLogModule gFileBlockCacheLog("FileBl
void
FileBlockCache::SetCacheFile(PRFileDesc* aFD)
{
MOZ_ASSERT(NS_IsMainThread());
FBC_LOG(LogLevel::Debug,
("FileBlockCache::SetFD(aFD=%p) mIsOpen=%d", aFD, mIsOpen));
+ if (!mIsOpen) {
+ // The cache has been shutdown while we were waiting for the file
+ // descriptor to come back in from the parent process.
+ if (aFD) {
+ // Close the file handle so it doesn't leak.
+ PR_Close(aFD);
+ }
+ mInitPromise->Reject(NS_ERROR_FAILURE, __func__);
+ return;
+ }
+
if (!aFD) {
// Failed to get a temporary file. Shutdown.
mInitPromise->Reject(NS_ERROR_FAILURE, __func__);
Close();
return;
}
{
MonitorAutoLock lock(mFileMonitor);