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
This commit is contained in:
Kris Maglione 2018-07-12 23:13:04 -07:00
parent 0fb080d242
commit c15ee94ddc
2 changed files with 3 additions and 18 deletions

View File

@ -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

View File

@ -8,6 +8,7 @@
#include <unistd.h>
#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);