[vlc-devel] commit: macosx/framework: Fix a bunch of track related leaks. (Pierre d' Herbemont )

git version control git at videolan.org
Fri Jan 29 11:49:33 CET 2010


vlc | branch: master | Pierre d'Herbemont <pdherbemont at free.fr> | Thu Jan 28 19:59:32 2010 +0100| [19fe54b3682a40aaae37b6f7754d225e90148780] | committer: Pierre d'Herbemont 

macosx/framework: Fix a bunch of track related leaks.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=19fe54b3682a40aaae37b6f7754d225e90148780
---

 projects/macosx/framework/Sources/VLCMediaPlayer.m |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/projects/macosx/framework/Sources/VLCMediaPlayer.m b/projects/macosx/framework/Sources/VLCMediaPlayer.m
index d8e4243..acc2232 100644
--- a/projects/macosx/framework/Sources/VLCMediaPlayer.m
+++ b/projects/macosx/framework/Sources/VLCMediaPlayer.m
@@ -61,6 +61,14 @@ NSString * VLCMediaPlayerStateToString(VLCMediaPlayerState state)
     return stateToStrings[state];
 }
 
+static inline libvlc_track_description_t *freeAndGetNextTrack(libvlc_track_description_t *track)
+{
+    libvlc_track_description_t *next = track->p_next;
+    free(track->psz_name);
+    free(track);
+    return next;
+}
+
 /* libvlc event callback */
 static void HandleMediaInstanceVolumeChanged(const libvlc_event_t * event, void * self)
 {
@@ -321,10 +329,7 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
     NSMutableArray *tempArray = [NSMutableArray array];
     while (currentTrack) {
         [tempArray addObject:[NSString stringWithUTF8String:currentTrack->psz_name]];
-        free(currentTrack->psz_name);
-        libvlc_track_description_t *tofree = currentTrack;
-        currentTrack = currentTrack->p_next;
-        free(tofree);
+        currentTrack = freeAndGetNextTrack(currentTrack);
     }
     return [NSArray arrayWithArray: tempArray];
 }
@@ -521,7 +526,7 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
     for (i = 0; i < count ; i++)
     {
         [tempArray addObject:[NSString stringWithUTF8String: tracks->psz_name]];
-        tracks = tracks->p_next;
+        tracks = freeAndGetNextTrack(tracks);
     }
     return [NSArray arrayWithArray: tempArray];
 }
@@ -571,7 +576,7 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
     for (i = 0; i < [self countOfTitles] ; i++)
     {
         [tempArray addObject:[NSString stringWithUTF8String: tracks->psz_name]];
-        tracks = tracks->p_next;
+        tracks = freeAndGetNextTrack(tracks);
     }
     return [NSArray arrayWithArray: tempArray];
 }
@@ -615,7 +620,7 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
     for (i = 0; i < count ; i++)
     {
         [tempArray addObject:[NSString stringWithUTF8String: tracks->psz_name]];
-        tracks = tracks->p_next;
+        tracks = freeAndGetNextTrack(tracks);
     }
 
     return [NSArray arrayWithArray: tempArray];




More information about the vlc-devel mailing list