From c15ee94ddc84a7bb0a7638f382b8bba614894ea3 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 12 Jul 2018 23:13:04 -0700 Subject: [PATCH] Bug 1475612: Fix double file close on background thread. r=erahm LSBUtils closes a file descriptor twice, once with fclose and then again with close. It also does this on a background thread, during startup, which means it tends to race with main thread code which opens files. This patch fixes that, and also removes a work-around for the issue in the MemMapSnapshot code. MozReview-Commit-ID: JdDHt9ayFEl --HG-- extra : rebase_source : 2000ede41108d6312734d8df7db98272b33528fa extra : amend_source : 1443a596fab3e3126a22d44787adaf5e12e4587c --- dom/ipc/MemMapSnapshot.cpp | 14 +------------- widget/LSBUtils.cpp | 7 ++----- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/dom/ipc/MemMapSnapshot.cpp b/dom/ipc/MemMapSnapshot.cpp index 866767071521..5552f6161a38 100644 --- a/dom/ipc/MemMapSnapshot.cpp +++ b/dom/ipc/MemMapSnapshot.cpp @@ -118,19 +118,7 @@ MemMapSnapshot::Freeze(AutoMemMap& aMem) MOZ_TRY(NS_NewNativeLocalFile(mPath, /* followLinks = */ false, getter_AddRefs(file))); - auto result = aMem.init(file); -#ifdef XP_LINUX - // On Linux automation runs, every few hundred thousand calls, our attempt to - // stat the file that we just successfully opened fails with EBADF (bug - // 1472889). Presumably this is a race with a background thread that double - // closes a file, but is difficult to diagnose, so work around it by making a - // second mapping attempt if the first one fails. - if (!result.isOk()) { - aMem.reset(); - result = aMem.init(file); - } -#endif - return result; + return aMem.init(file); } #else diff --git a/widget/LSBUtils.cpp b/widget/LSBUtils.cpp index 344fea4d0b67..1b0b2bdc183e 100644 --- a/widget/LSBUtils.cpp +++ b/widget/LSBUtils.cpp @@ -8,6 +8,7 @@ #include #include "base/process_util.h" +#include "mozilla/FileUtils.h" namespace mozilla { namespace widget { @@ -47,7 +48,7 @@ GetLSBRelease(nsACString& aDistributor, return false; } - FILE* stream = fdopen(pipefd[0], "r"); + ScopedCloseFile stream(fdopen(pipefd[0], "r")); if (!stream) { NS_WARNING("Could not wrap fd!"); close(pipefd[0]); @@ -62,12 +63,8 @@ GetLSBRelease(nsACString& aDistributor, dist, desc, release, codename) != 4) { NS_WARNING("Failed to parse lsb_release!"); - fclose(stream); - close(pipefd[0]); return false; } - fclose(stream); - close(pipefd[0]); aDistributor.Assign(dist); aDescription.Assign(desc);