зеркало из https://github.com/mozilla/gecko-dev.git
Fix bug 124517 -- double delete caused by making more than one nsMacMemoryCushion object (one for each event loop). This should fix a ton of random crashes on Mac. r=pinkerton, sr=beard
This commit is contained in:
Родитель
49d0a35f7d
Коммит
db23565e42
|
@ -93,22 +93,17 @@ NS_IMETHODIMP nsAppShell::SetDispatchListener(nsDispatchListener* aDispatchListe
|
|||
|
||||
NS_IMETHODIMP nsAppShell::Create(int* argc, char ** argv)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = NS_GetCurrentToolkit(getter_AddRefs(mToolkit));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsIToolkit* toolkit = mToolkit.get();
|
||||
mMacPump.reset(new nsMacMessagePump(static_cast<nsToolkit*>(toolkit)));
|
||||
mMacMemoryCushion.reset(new nsMacMemoryCushion());
|
||||
nsresult rv = NS_GetCurrentToolkit(getter_AddRefs(mToolkit));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (!mMacPump.get() || !mMacMemoryCushion.get())
|
||||
nsIToolkit* toolkit = mToolkit.get();
|
||||
mMacPump.reset(new nsMacMessagePump(static_cast<nsToolkit*>(toolkit)));
|
||||
|
||||
if (!mMacPump.get() || ! nsMacMemoryCushion::EnsureMemoryCushion())
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
OSErr err = mMacMemoryCushion->Init(nsMacMemoryCushion::kMemoryBufferSize, nsMacMemoryCushion::kMemoryReserveSize);
|
||||
if (err != noErr)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -121,7 +116,6 @@ NS_IMETHODIMP nsAppShell::Run(void)
|
|||
if (!mMacPump.get())
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
mMacMemoryCushion->StartRepeating();
|
||||
mMacPump->StartRunning();
|
||||
mMacPump->DoMessagePump();
|
||||
|
||||
|
|
|
@ -56,8 +56,6 @@
|
|||
using std::auto_ptr;
|
||||
|
||||
class nsMacMessagePump;
|
||||
class nsMacMemoryCushion;
|
||||
|
||||
|
||||
class nsAppShell : public nsIAppShell
|
||||
{
|
||||
|
@ -72,7 +70,6 @@ class nsAppShell : public nsIAppShell
|
|||
nsDispatchListener *mDispatchListener; // note: we don't own this, but it can be NULL
|
||||
nsCOMPtr<nsIToolkit> mToolkit;
|
||||
auto_ptr<nsMacMessagePump> mMacPump;
|
||||
auto_ptr<nsMacMemoryCushion> mMacMemoryCushion;
|
||||
PRBool mExitCalled;
|
||||
static PRBool mInitializedToolbox;
|
||||
};
|
||||
|
|
|
@ -384,9 +384,15 @@ nsMacMemoryCushion::nsMacMemoryCushion()
|
|||
|
||||
nsMacMemoryCushion::~nsMacMemoryCushion()
|
||||
{
|
||||
StopRepeating();
|
||||
::SetGrowZone(nsnull);
|
||||
|
||||
NS_ASSERTION(sMemoryReserve, "Memory reserve was nil");
|
||||
if (sMemoryReserve)
|
||||
{
|
||||
::DisposeHandle(sMemoryReserve);
|
||||
sMemoryReserve = nil;
|
||||
}
|
||||
|
||||
if (mBufferHandle)
|
||||
::DisposeHandle(mBufferHandle);
|
||||
|
@ -460,3 +466,26 @@ pascal long nsMacMemoryCushion::GrowZoneProc(Size amountNeeded)
|
|||
return freedMem;
|
||||
}
|
||||
|
||||
std::auto_ptr<nsMacMemoryCushion> gMemoryCushion;
|
||||
|
||||
Boolean nsMacMemoryCushion::EnsureMemoryCushion()
|
||||
{
|
||||
if (!gMemoryCushion.get())
|
||||
{
|
||||
nsMacMemoryCushion* softFluffyCushion = new nsMacMemoryCushion();
|
||||
if (!softFluffyCushion) return false;
|
||||
|
||||
OSErr err = softFluffyCushion->Init(nsMacMemoryCushion::kMemoryBufferSize, nsMacMemoryCushion::kMemoryReserveSize);
|
||||
if (err != noErr)
|
||||
{
|
||||
delete softFluffyCushion;
|
||||
return false;
|
||||
}
|
||||
|
||||
gMemoryCushion.reset(softFluffyCushion);
|
||||
softFluffyCushion->StartRepeating();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
#ifndef TOOLKIT_H
|
||||
#define TOOLKIT_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "nsIToolkit.h"
|
||||
#include "nsRepeater.h"
|
||||
|
||||
|
@ -166,10 +168,11 @@ protected:
|
|||
Boolean RecoverMemoryReserve(Size reserveSize);
|
||||
|
||||
|
||||
static pascal long GrowZoneProc(Size amountNeeded);
|
||||
|
||||
public:
|
||||
|
||||
static pascal long GrowZoneProc(Size amountNeeded);
|
||||
|
||||
static Boolean EnsureMemoryCushion();
|
||||
|
||||
protected:
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче