MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL() leaks an NSMutableArray
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Jun 2014 16:22:51 +0000 (16:22 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Jun 2014 16:22:51 +0000 (16:22 +0000)
<http://webkit.org/b/134052>

Reviewed by Eric Carlson.

Fixes the following static analyzer warning:

    WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:688:43: warning: Potential leak of an object stored into 'outOfBandTracks'
            NSMutableArray* outOfBandTracks = [[NSMutableArray alloc] init];
                                              ^

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL):
Use RetainPtr<NSMutableArray> to prevent a leak.  Use
Objective-C literals to clean up the code.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

index b9ada941aabf214b2b3bb1aecf95f21145acb7b4..e39f71506e7fe3f857c5c0b8947d2e2759fcd5f6 100644 (file)
@@ -1,3 +1,21 @@
+2014-06-19  David Kilzer  <ddkilzer@apple.com>
+
+        MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL() leaks an NSMutableArray
+        <http://webkit.org/b/134052>
+
+        Reviewed by Eric Carlson.
+
+        Fixes the following static analyzer warning:
+
+            WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:688:43: warning: Potential leak of an object stored into 'outOfBandTracks'
+                    NSMutableArray* outOfBandTracks = [[NSMutableArray alloc] init];
+                                                      ^
+
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL):
+        Use RetainPtr<NSMutableArray> to prevent a leak.  Use
+        Objective-C literals to clean up the code.
+
 2014-06-18  Zan Dobersek  <zdobersek@igalia.com>
 
         ScriptExecutionContext::Task, FileThread::Task parameters should be values
 2014-06-18  Zan Dobersek  <zdobersek@igalia.com>
 
         ScriptExecutionContext::Task, FileThread::Task parameters should be values
index a955015904e8ae8441330da30b5efba54baeeab9..14a8b06cbd61126cf4d3116a799a2b9f7ef55347 100644 (file)
@@ -685,24 +685,23 @@ void MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL(const String& url)
 #if ENABLE(AVF_CAPTIONS)
     const Vector<RefPtr<PlatformTextTrack>>& outOfBandTrackSources = player()->outOfBandTrackSources();
     if (!outOfBandTrackSources.isEmpty()) {
 #if ENABLE(AVF_CAPTIONS)
     const Vector<RefPtr<PlatformTextTrack>>& outOfBandTrackSources = player()->outOfBandTrackSources();
     if (!outOfBandTrackSources.isEmpty()) {
-        NSMutableArray* outOfBandTracks = [[NSMutableArray alloc] init];
+        RetainPtr<NSMutableArray> outOfBandTracks = adoptNS([[NSMutableArray alloc] init]);
         for (auto& trackSource : outOfBandTrackSources) {
             RetainPtr<CFStringRef> label = trackSource->label().createCFString();
             RetainPtr<CFStringRef> language = trackSource->language().createCFString();
             RetainPtr<CFStringRef> uniqueID = String::number(trackSource->uniqueId()).createCFString();
             RetainPtr<CFStringRef> url = trackSource->url().createCFString();
         for (auto& trackSource : outOfBandTrackSources) {
             RetainPtr<CFStringRef> label = trackSource->label().createCFString();
             RetainPtr<CFStringRef> language = trackSource->language().createCFString();
             RetainPtr<CFStringRef> uniqueID = String::number(trackSource->uniqueId()).createCFString();
             RetainPtr<CFStringRef> url = trackSource->url().createCFString();
-            [outOfBandTracks addObject:
-                [NSDictionary dictionaryWithObjectsAndKeys:
-                    reinterpret_cast<const NSString*>(label.get()), AVOutOfBandAlternateTrackDisplayNameKey,
-                    reinterpret_cast<const NSString*>(language.get()), AVOutOfBandAlternateTrackExtendedLanguageTagKey,
-                    [NSNumber numberWithBool: (trackSource->isDefault() ? YES : NO)], AVOutOfBandAlternateTrackIsDefaultKey,
-                    reinterpret_cast<const NSString*>(uniqueID.get()), AVOutOfBandAlternateTrackIdentifierKey,
-                    reinterpret_cast<const NSString*>(url.get()), AVOutOfBandAlternateTrackSourceKey,
-                    mediaDescriptionForKind(trackSource->kind()), AVOutOfBandAlternateTrackMediaCharactersticsKey,
-                    nil]];
+            [outOfBandTracks.get() addObject:@{
+                AVOutOfBandAlternateTrackDisplayNameKey: reinterpret_cast<const NSString*>(label.get()),
+                AVOutOfBandAlternateTrackExtendedLanguageTagKey: reinterpret_cast<const NSString*>(language.get()),
+                AVOutOfBandAlternateTrackIsDefaultKey: trackSource->isDefault() ? @YES : @NO,
+                AVOutOfBandAlternateTrackIdentifierKey: reinterpret_cast<const NSString*>(uniqueID.get()),
+                AVOutOfBandAlternateTrackSourceKey: reinterpret_cast<const NSString*>(url.get()),
+                AVOutOfBandAlternateTrackMediaCharactersticsKey: mediaDescriptionForKind(trackSource->kind()),
+            }];
         }
 
         }
 
-        [options.get() setObject: outOfBandTracks forKey: AVURLAssetOutOfBandAlternateTracksKey];
+        [options.get() setObject:outOfBandTracks.get() forKey:AVURLAssetOutOfBandAlternateTracksKey];
     }
 #endif
 
     }
 #endif