Bug 1343752 - Guard against modules list shrinking between EnumProcessModules calls. (telemetry/) r=marco
authorDavid Major <dmajor@mozilla.com>
Mon, 06 Mar 2017 14:10:36 +1300
changeset 375070 7c3ed29c6ffb3483b4ddf25a82183480bc013a9d
parent 375069 4087fb7a5fb525c547e14e00e50b2229484cdd5c
child 375071 d01cc63b45043da203c2324c14658f8c5854156e
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarco
bugs1343752
milestone54.0a1
Bug 1343752 - Guard against modules list shrinking between EnumProcessModules calls. (telemetry/) r=marco
tools/profiler/core/shared-libraries-win32.cc
--- a/tools/profiler/core/shared-libraries-win32.cc
+++ b/tools/profiler/core/shared-libraries-win32.cc
@@ -121,16 +121,20 @@ SharedLibraryInfo SharedLibraryInfo::Get
     if (!EnumProcessModules(hProcess, nullptr, 0, &modulesSize)) {
       return sharedLibraryInfo;
     }
     modulesNum = modulesSize / sizeof(HMODULE);
     hMods = mozilla::MakeUnique<HMODULE[]>(modulesNum);
     if (!EnumProcessModules(hProcess, hMods.get(), modulesNum * sizeof(HMODULE), &modulesSize)) {
       return sharedLibraryInfo;
     }
+    // The list may have shrunk between calls
+    if (modulesSize / sizeof(HMODULE) < modulesNum) {
+      modulesNum = modulesSize / sizeof(HMODULE);
+    }
   }
 
   for (unsigned int i = 0; i < modulesNum; i++) {
     nsID pdbSig;
     uint32_t pdbAge;
     nsAutoString pdbNameStr;
     char *pdbName = NULL;
     std::string breakpadId;
@@ -140,17 +144,17 @@ SharedLibraryInfo SharedLibraryInfo::Get
       continue;
     }
 
     MODULEINFO module = {0};
     if (!GetModuleInformation(hProcess, hMods[i], &module, sizeof(MODULEINFO))) {
       continue;
     }
 
-    // Load the module again to make sure that its handle will remain remain
+    // Load the module again to make sure that its handle will remain
     // valid as we attempt to read the PDB information from it.  We load the
     // DLL as a datafile so that if the module actually gets unloaded between
     // the call to EnumProcessModules and the following LoadLibraryEx, we don't
     // end up running the now newly loaded module's DllMain function.  If the
     // module is already loaded, LoadLibraryEx just increments its refcount.
     //
     // Note that because of the race condition above, merely loading the DLL
     // again is not safe enough, therefore we also need to make sure that we