Reviewed by andersca.
authorkdecker <kdecker@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 27 Jan 2007 00:52:16 +0000 (00:52 +0000)
committerkdecker <kdecker@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 27 Jan 2007 00:52:16 +0000 (00:52 +0000)
        Fixed: <rdar://problem/4946922> WebBaseNetscapePluginView leaks memory
        http://bugs.webkit.org/show_bug.cgi?id=11523

        * Plugins/WebBaseNetscapePluginStream.m:
       (-[WebBaseNetscapePluginStream setPlugin:]): Calls -[WebBaseNetscapePluginView disconnectStream:]
        * Plugins/WebBaseNetscapePluginView.h: Added disconnectStream: to header.
        * Plugins/WebBaseNetscapePluginView.mm:
        (-[WebBaseNetscapePluginView stop]): Make a copy of the streams collection prior to calling stop all streams.
        This is necessary because calling stop has the side effect of removing the stream from this same collection.
        (-[WebBaseNetscapePluginView disconnectStream:]): Added. Removes the stream from the streams collection.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@19167 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/ChangeLog
WebKit/Plugins/WebBaseNetscapePluginStream.m
WebKit/Plugins/WebBaseNetscapePluginView.h
WebKit/Plugins/WebBaseNetscapePluginView.mm

index 437c9f3..d3e6872 100644 (file)
@@ -1,3 +1,18 @@
+2007-01-26  Kevin Decker <kdecker@apple.com>
+
+        Reviewed by andersca.
+
+        Fixed: <rdar://problem/4946922> WebBaseNetscapePluginView leaks memory
+        http://bugs.webkit.org/show_bug.cgi?id=11523
+
+        * Plugins/WebBaseNetscapePluginStream.m:
+       (-[WebBaseNetscapePluginStream setPlugin:]): Calls -[WebBaseNetscapePluginView disconnectStream:]
+        * Plugins/WebBaseNetscapePluginView.h: Added disconnectStream: to header.
+        * Plugins/WebBaseNetscapePluginView.mm:
+        (-[WebBaseNetscapePluginView stop]): Make a copy of the streams collection prior to calling stop all streams.
+        This is necessary because calling stop has the side effect of removing the stream from this same collection.
+        (-[WebBaseNetscapePluginView disconnectStream:]): Added. Removes the stream from the streams collection.
+
 2007-01-25  Kevin Decker <kdecker@apple.com>
 
         Backed out my last patch because it crashes espn.com. Stay tuned for a newer version..
index 82dec94..3b58daa 100644 (file)
@@ -174,15 +174,19 @@ static char *CarbonPathFromPOSIXPath(const char *posixPath);
         NPP_DestroyStream = [pluginPackage NPP_DestroyStream];
         NPP_URLNotify = [pluginPackage NPP_URLNotify];
     } else {
+        WebBaseNetscapePluginView *view = pluginView;
+
         plugin = NULL;
-        [pluginView release];
-        pluginView = nil;
         NPP_NewStream = NULL;
         NPP_WriteReady = NULL;
         NPP_Write = NULL;
         NPP_StreamAsFile = NULL;
         NPP_DestroyStream = NULL;
         NPP_URLNotify = NULL;
+        pluginView = nil;
+
+        [view disconnectStream:self];
+        [view release];
     }
 }
 
index 22b76e5..3b5687d 100644 (file)
@@ -151,6 +151,7 @@ typedef union PluginPort {
 - (void)setMode:(int)theMode;
 - (void)viewWillMoveToHostWindow:(NSWindow *)hostWindow;
 - (void)viewDidMoveToHostWindow;
+- (void)disconnectStream:(WebBaseNetscapePluginStream*)stream;
 
 // Returns the NPObject that represents the plugin interface.
 // The return value is expected to be retained.
index 9f821f3..dc30e1e 100644 (file)
@@ -1290,10 +1290,13 @@ static OSStatus TSMEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEve
         return;
     
     isStarted = NO;
-    
-    // Stop any active streams
-    [streams makeObjectsPerformSelector:@selector(stop)];
-    
+    // To stop active streams it's necessary to invoke makeObjectsPerformSelector on a copy 
+    // of streams. This is because calling -[WebNetscapePluginStream stop] also has the side effect
+    // of removing a stream from this collection.
+    NSArray *streamsCopy = [streams copy];
+    [streamsCopy makeObjectsPerformSelector:@selector(stop)];
+    [streamsCopy release];
+   
     // Stop the null events
     [self stopNullEvents];
 
@@ -1496,6 +1499,11 @@ static OSStatus TSMEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEve
     free(cValues);
 }
 
+- (void)disconnectStream:(WebBaseNetscapePluginStream*)stream
+{
+    [streams removeObjectIdenticalTo:stream];    
+}
+
 - (void)dealloc
 {
     ASSERT(!isStarted);