Bug 1343752 - Guard against modules list shrinking between EnumProcessModules calls (media/) r=cpearce
authorDavid Major <dmajor@mozilla.com>
Mon, 06 Mar 2017 14:10:04 +1300
changeset 346042 4087fb7a5fb525c547e14e00e50b2229484cdd5c
parent 346041 e7e495f38cf3cb711446260b9bd81f226d1507f0
child 346043 7c3ed29c6ffb3483b4ddf25a82183480bc013a9d
push id31452
push usercbook@mozilla.com
push dateMon, 06 Mar 2017 09:54:03 +0000
treeherdermozilla-central@966464a68a2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1343752
milestone54.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 1343752 - Guard against modules list shrinking between EnumProcessModules calls (media/) r=cpearce
dom/media/platforms/wmf/WMFVideoMFTManager.cpp
--- a/dom/media/platforms/wmf/WMFVideoMFTManager.cpp
+++ b/dom/media/platforms/wmf/WMFVideoMFTManager.cpp
@@ -203,21 +203,29 @@ FindDXVABlacklistedDLL(
   // Adopt new pref now, so we don't work on it again.
   aDLLBlacklistingCache->mBlacklistPref = aBlacklist;
 
   HANDLE hProcess = GetCurrentProcess();
   mozilla::UniquePtr<HMODULE[]> hMods;
   unsigned int modulesNum = 0;
   if (hProcess != NULL) {
     DWORD modulesSize;
-    EnumProcessModules(hProcess, nullptr, 0, &modulesSize);
-    modulesNum = modulesSize / sizeof(HMODULE);
-    hMods = mozilla::MakeUnique<HMODULE[]>(modulesNum);
-    EnumProcessModules(
-      hProcess, hMods.get(), modulesNum * sizeof(HMODULE), &modulesSize);
+    if (EnumProcessModules(hProcess, nullptr, 0, &modulesSize)) {
+      modulesNum = modulesSize / sizeof(HMODULE);
+      hMods = mozilla::MakeUnique<HMODULE[]>(modulesNum);
+      if (EnumProcessModules(hProcess, hMods.get(),
+            modulesNum * sizeof(HMODULE), &modulesSize)) {
+        // The list may have shrunk
+        if (modulesSize / sizeof(HMODULE) < modulesNum) {
+          modulesNum = modulesSize / sizeof(HMODULE);
+        }
+      } else {
+        modulesNum = 0;
+      }
+    }
   }
 
   // media.wmf.disable-d3d*-for-dlls format: (whitespace is trimmed)
   // "dll1.dll: 1.2.3.4[, more versions...][; more dlls...]"
   nsTArray<nsCString> dlls;
   SplitAt(";", aBlacklist, dlls);
   for (const auto& dll : dlls) {
     nsTArray<nsCString> nameAndVersions;