bug 559075 - use a local autorelease pool in nsCocoaWindow and nsChildView methods used during hidden window creation. r=josh

This commit is contained in:
Jonathan Kew 2010-04-13 21:36:03 +01:00
parent ac0c03fe97
commit 9448cba17e
3 changed files with 30 additions and 5 deletions

View File

@ -519,6 +519,11 @@ nsresult nsChildView::Create(nsIWidget *aParent,
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
// Because the hidden window is created outside of an event loop,
// we need to provide an autorelease pool to avoid leaking cocoa objects
// (see bug 559075).
nsAutoreleasePool localPool;
// See NSView (MethodSwizzling) below.
if (!gChildViewMethodsSwizzled) {
nsToolkit::SwizzleMethods([NSView class], @selector(mouseDownCanMoveWindow),
@ -882,6 +887,11 @@ NS_IMETHODIMP nsChildView::Show(PRBool aState)
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
if (aState != mVisible) {
// Provide an autorelease pool because this gets called during startup
// on the "hidden window", resulting in cocoa object leakage if there's
// no pool in place.
nsAutoreleasePool localPool;
[mView setHidden:!aState];
mVisible = aState;
if (!mVisible)
@ -6254,11 +6264,10 @@ ChildViewMouseTracker::WindowAcceptsEvent(NSWindow* aWindow, NSEvent* anEvent)
OSStatus PluginKeyEventsHandler(EventHandlerCallRef inHandlerRef,
EventRef inEvent, void *userData)
{
id arp = [[NSAutoreleasePool alloc] init];
nsAutoreleasePool localPool;
TSMDocumentID activeDoc = ::TSMGetActiveDocument();
if (!activeDoc) {
[arp release];
return eventNotHandledErr;
}
@ -6268,7 +6277,6 @@ OSStatus PluginKeyEventsHandler(EventHandlerCallRef inHandlerRef,
if (status != noErr)
target = nil;
if (!target) {
[arp release];
return eventNotHandledErr;
}
@ -6276,13 +6284,11 @@ OSStatus PluginKeyEventsHandler(EventHandlerCallRef inHandlerRef,
status = ::GetEventParameter(inEvent, kEventParamTextInputSendKeyboardEvent,
typeEventRef, NULL, sizeof(EventRef), NULL, &keyEvent);
if ((status != noErr) || !keyEvent) {
[arp release];
return eventNotHandledErr;
}
[target processPluginKeyEvent:keyEvent];
[arp release];
return noErr;
}

View File

@ -64,6 +64,21 @@ private:
id mObject; // [STRONG]
};
// Provide a local autorelease pool for the remainder of a method's execution.
class nsAutoreleasePool {
public:
nsAutoreleasePool()
{
mLocalPool = [[NSAutoreleasePool alloc] init];
}
~nsAutoreleasePool()
{
[mLocalPool release];
}
private:
NSAutoreleasePool *mLocalPool;
};
@interface NSApplication (Undocumented)
// Present in all versions of OS X from (at least) 10.2.8 through 10.5.

View File

@ -251,6 +251,10 @@ nsresult nsCocoaWindow::Create(nsIWidget *aParent,
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
// Because the hidden window is created outside of an event loop,
// we have to provide an autorelease pool (see bug 559075).
nsAutoreleasePool localPool;
if (!WindowSizeAllowed(aRect.width, aRect.height))
return NS_ERROR_FAILURE;