Bug 780272 - Audit calls to MozillaUnRegisterDebugFD. r=jlebar.
authorRafael Ávila de Espíndola <respindola@mozilla.com>
Fri, 10 Aug 2012 12:40:21 -0400
changeset 102103 c7af21dd3f06b88323bd17fc3dbc16b7ce1b79e5
parent 102102 f2591f1d1fa05fdc5e4b1d6af38cc9e7f0047c5a
child 102104 cefb4ae9e7d5aa7622df9577c1914b3592c4654d
push id13315
push userrespindola@mozilla.com
push dateFri, 10 Aug 2012 16:42:24 +0000
treeherdermozilla-inbound@c7af21dd3f06 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlebar
bugs780272
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 780272 - Audit calls to MozillaUnRegisterDebugFD. r=jlebar.
toolkit/components/startup/nsAppStartup.cpp
tools/trace-malloc/lib/nsTraceMalloc.c
xpcom/base/nsTraceRefcntImpl.cpp
xpcom/build/mozPoisonWrite.h
xpcom/build/mozPoisonWriteMac.cpp
xpcom/build/mozPoisonWriteStub.cpp
--- a/toolkit/components/startup/nsAppStartup.cpp
+++ b/toolkit/components/startup/nsAppStartup.cpp
@@ -338,18 +338,18 @@ RecordShutdownEndTimeStamp() {
   int fd = fileno(f);
   MozillaRegisterDebugFD(fd);
 
   TimeStamp now = TimeStamp::Now();
   MOZ_ASSERT(now >= gRecordedShutdownStartTime);
   TimeDuration diff = now - gRecordedShutdownStartTime;
   uint32_t diff2 = diff.ToMilliseconds();
   int written = fprintf(f, "%d\n", diff2);
+  MozillaUnRegisterDebugFILE(f);
   int rv = fclose(f);
-  MozillaUnRegisterDebugFD(fd);
   if (written < 0 || rv != 0) {
     PR_Delete(tmpName.get());
     return;
   }
   PR_Delete(name.get());
   PR_Rename(tmpName.get(), name.get());
 }
 }
--- a/tools/trace-malloc/lib/nsTraceMalloc.c
+++ b/tools/trace-malloc/lib/nsTraceMalloc.c
@@ -1772,19 +1772,18 @@ NS_TraceMallocDumpAllocations(const char
     ofp = fopen(pathname, WRITE_FLAGS);
     if (ofp) {
         MozillaRegisterDebugFD(fileno(ofp));
         if (allocations) {
             PL_HashTableEnumerateEntries(allocations, allocation_enumerator,
                                          ofp);
         }
         rv = ferror(ofp) ? -1 : 0;
-        fd = fileno(ofp);
-        fclose(ofp); /* May call write. */
-        MozillaUnRegisterDebugFD(fd);
+        MozillaUnRegisterDebugFILE(ofp);
+        fclose(ofp);
     } else {
         rv = -1;
     }
 
     TM_EXIT_LOCK_AND_UNSUPPRESS_TRACING(t);
 
     return rv;
 }
--- a/xpcom/base/nsTraceRefcntImpl.cpp
+++ b/xpcom/base/nsTraceRefcntImpl.cpp
@@ -1236,20 +1236,18 @@ void
 nsTraceRefcntImpl::Startup()
 {
 }
 
 static void maybeUnregisterAndCloseFile(FILE *&f) {
   if (!f)
     return;
 
-  int fd = fileno(f);
+  MozillaUnRegisterDebugFILE(f);
   fclose(f);
-  if (fd != 1 && fd != 2)
-    MozillaUnRegisterDebugFD(fd);
   f = nullptr;
 }
 
 void
 nsTraceRefcntImpl::Shutdown()
 {
 #ifdef NS_IMPL_REFCNT_LOGGING
 
--- a/xpcom/build/mozPoisonWrite.h
+++ b/xpcom/build/mozPoisonWrite.h
@@ -1,19 +1,21 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* vim:set ts=4 sw=4 sts=4 ci et: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Types.h"
+#include <stdio.h>
 
 MOZ_BEGIN_EXTERN_C
   void MozillaRegisterDebugFD(int fd);
   void MozillaUnRegisterDebugFD(int fd);
+  void MozillaUnRegisterDebugFILE(FILE *f);
 MOZ_END_EXTERN_C
 
 #ifdef __cplusplus
 namespace mozilla {
 void PoisonWrite();
 void DisableWritePoisoning();
 }
 #endif
--- a/xpcom/build/mozPoisonWriteMac.cpp
+++ b/xpcom/build/mozPoisonWriteMac.cpp
@@ -447,16 +447,23 @@ extern "C" {
     }
     void MozillaUnRegisterDebugFD(int fd) {
         MyAutoLock lockedScope;
         std::vector<int> &Vec = getDebugFDs();
         std::vector<int>::iterator i = std::find(Vec.begin(), Vec.end(), fd);
         MOZ_ASSERT(i != Vec.end());
         Vec.erase(i);
     }
+    void MozillaUnRegisterDebugFILE(FILE *f) {
+        int fd = fileno(f);
+        if (fd == 1 || fd == 2)
+            return;
+        fflush(f);
+        MozillaUnRegisterDebugFD(fd);
+    }
 }
 
 namespace mozilla {
 void PoisonWrite() {
     PoisoningDisabled = false;
 
     nsCOMPtr<nsIFile> mozFile;
     NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(mozFile));
--- a/xpcom/build/mozPoisonWriteStub.cpp
+++ b/xpcom/build/mozPoisonWriteStub.cpp
@@ -1,18 +1,21 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* vim:set ts=4 sw=4 sts=4 ci et: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include <stdio.h>
 namespace mozilla {
 void PoisonWrite() {
 }
 void DisableWritePoisoning() {
 }
 }
 extern "C" {
     void MozillaRegisterDebugFD(int fd) {
     }
     void MozillaUnRegisterDebugFD(int fd) {
     }
+    void MozillaUnRegisterDebugFILE(FILE *f) {
+    }
 }