From 7e813c23e3520ea2bd69b5489a2731792a5f6e05 Mon Sep 17 00:00:00 2001 From: Jim Mathies Date: Thu, 7 Jan 2016 13:57:42 -0600 Subject: [PATCH] Bug 1107702 - Try to avoid internal memory exhaustion problems with the Windows api GetAdaptersInfo by making a priming call to the api during startup. r=jesup --- dom/media/MediaManager.cpp | 25 +++++++++++++++++++++++++ dom/media/MediaManager.h | 1 + layout/build/nsLayoutStatics.cpp | 1 + 3 files changed, 27 insertions(+) diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 25302692ae2..11f24732064 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -78,6 +78,9 @@ #endif #if defined (XP_WIN) #include "mozilla/WindowsVersion.h" +#include +#include +#include #endif // GetCurrentTime is defined in winbase.h as zero argument macro forwarding to @@ -1640,6 +1643,28 @@ MediaManager::GetNonE10sParent() return mNonE10sParent; } +/* static */ void +MediaManager::StartupInit() +{ +#ifdef WIN32 + if (IsVistaOrLater() && !IsWin8OrLater()) { + // Bug 1107702 - Older Windows fail in GetAdaptersInfo (and others) if the + // first(?) call occurs after the process size is over 2GB (kb/2588507). + // Attempt to 'prime' the pump by making a call at startup. + unsigned long out_buf_len = sizeof(IP_ADAPTER_INFO); + PIP_ADAPTER_INFO pAdapterInfo = (IP_ADAPTER_INFO *) moz_xmalloc(out_buf_len); + if (GetAdaptersInfo(pAdapterInfo, &out_buf_len) == ERROR_BUFFER_OVERFLOW) { + free(pAdapterInfo); + pAdapterInfo = (IP_ADAPTER_INFO *) moz_xmalloc(out_buf_len); + GetAdaptersInfo(pAdapterInfo, &out_buf_len); + } + if (pAdapterInfo) { + free(pAdapterInfo); + } + } +#endif +} + /* static */ void MediaManager::PostTask(const tracked_objects::Location& from_here, Task* task) diff --git a/dom/media/MediaManager.h b/dom/media/MediaManager.h index fc1c7bc4118..370bf9e3a1e 100644 --- a/dom/media/MediaManager.h +++ b/dom/media/MediaManager.h @@ -415,6 +415,7 @@ public: // from MediaManager thread. static MediaManager* Get(); static MediaManager* GetIfExists(); + static void StartupInit(); static void PostTask(const tracked_objects::Location& from_here, Task* task); #ifdef DEBUG static bool IsInMediaThread(); diff --git a/layout/build/nsLayoutStatics.cpp b/layout/build/nsLayoutStatics.cpp index 2da3938d6c9..f72ca91dcfd 100644 --- a/layout/build/nsLayoutStatics.cpp +++ b/layout/build/nsLayoutStatics.cpp @@ -261,6 +261,7 @@ nsLayoutStatics::Initialize() } AsyncLatencyLogger::InitializeStatics(); + MediaManager::StartupInit(); CubebUtils::InitLibrary(); nsContentSink::InitializeStatics();