]> git.sesse.net Git - vlc/blobdiff - modules/misc/playlist/m3u.c
Fix memleaks (corner case).
[vlc] / modules / misc / playlist / m3u.c
index 8f9e509853784964675d9228b095474184bfff2e..4cc4a1d405631a70a4cb121e90635c2e2e2fc40a 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
 #include <vlc_interface.h>
 #include <vlc_playlist.h>
 #include <vlc_input.h>
@@ -34,6 +37,8 @@
 
 #include <errno.h>                                                 /* ENOMEM */
 
+#include <assert.h>
+
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -51,8 +56,7 @@ static void DoChildren( playlist_t *p_playlist, playlist_export_t *p_export,
     for( i = 0; i< p_root->i_children ; i++)
     {
         playlist_item_t *p_current = p_root->pp_children[i];
-        if( !p_current )
-            continue;
+        assert( p_current );
 
         if( p_current->i_flags & PLAYLIST_SAVE_FLAG )
             continue;
@@ -63,36 +67,36 @@ static void DoChildren( playlist_t *p_playlist, playlist_export_t *p_export,
             continue;
         }
 
-        assert( p_current->p_input->psz_uri );
-
         /* General info */
-        if( p_current->p_input->psz_name &&
-             strcmp( p_current->p_input->psz_uri,
-                     p_current->p_input->psz_name ) )
+
+        char *psz_uri = input_item_GetURI( p_current->p_input );
+
+        assert( psz_uri );
+
+        char *psz_name = input_item_GetName( p_current->p_input );
+        if( psz_name && strcmp( psz_uri, psz_name ) )
         {
-            char *psz_artist = p_current->p_input->p_meta->psz_artist ?
-                               strdup( p_current->p_input->p_meta->psz_artist ):
-                               strdup( "" );
+            char *psz_artist = input_item_GetArtist( p_current->p_input );
+            if( psz_artist == NULL ) psz_artist = strdup( "" );
+            mtime_t i_duration = input_item_GetDuration( p_current->p_input );
             if( psz_artist && *psz_artist )
             {
                 /* write EXTINF with artist */
                 fprintf( p_export->p_file, "#EXTINF:%i,%s - %s\n",
-                          (int)( p_current->p_input->i_duration/1000000 ),
-                          psz_artist,
-                          p_current->p_input->psz_name);
+                          (int)( i_duration / 1000000 ), psz_artist, psz_name);
             }
             else
             {
                 /* write EXTINF without artist */
                 fprintf( p_export->p_file, "#EXTINF:%i,%s\n",
-                         (int)( p_current->p_input->i_duration/1000000 ),
-                          p_current->p_input->psz_name);
+                         (int)( i_duration / 1000000 ), psz_name);
             }
-            if( psz_artist )
-                free( psz_artist );
+            free( psz_artist );
         }
+        free( psz_name );
 
         /* VLC specific options */
+        vlc_mutex_lock( &p_current->p_input->lock );
         for( j = 0; j < p_current->p_input->i_options; j++ )
         {
             fprintf( p_export->p_file, "#EXTVLCOPT:%s\n",
@@ -100,9 +104,10 @@ static void DoChildren( playlist_t *p_playlist, playlist_export_t *p_export,
                      p_current->p_input->ppsz_options[j] + 1 :
                      p_current->p_input->ppsz_options[j] );
         }
+        vlc_mutex_unlock( &p_current->p_input->lock );
 
-        fprintf( p_export->p_file, "%s\n",
-                 p_current->p_input->psz_uri );
+        fprintf( p_export->p_file, "%s\n", psz_uri );
+        free( psz_uri );
     }
 }
 
@@ -119,4 +124,3 @@ int Export_M3U( vlc_object_t *p_this )
     DoChildren( p_playlist, p_export, p_export->p_root );
     return VLC_SUCCESS;
 }
-