]> git.sesse.net Git - vlc/blobdiff - src/playlist/loadsave.c
Fix resource leak when loadsave fail (CID 94)
[vlc] / src / playlist / loadsave.c
index 4015c1e93ba7c7a6eda653271d3e6a8546b8ef30..537a3de06cf7340895d195bb145b28b8f0496e91 100644 (file)
@@ -44,21 +44,21 @@ int playlist_Export( playlist_t * p_playlist, const char *psz_filename ,
 
     if( p_export_root == NULL ) return VLC_EGENERIC;
 
-    msg_Info( p_playlist, "saving %s to file %s",
+    msg_Dbg( p_playlist, "saving %s to file %s",
                     p_export_root->p_input->psz_name, psz_filename );
 
     /* Prepare the playlist_export_t structure */
     p_export = (playlist_export_t *)malloc( sizeof(playlist_export_t) );
     if( !p_export)
         return VLC_ENOMEM;
-    p_export->psz_filename = NULL;
-    if ( psz_filename )
-        p_export->psz_filename = strdup( psz_filename );
+    p_export->psz_filename = psz_filename ? strdup( psz_filename ) : NULL;
     p_export->p_file = utf8_fopen( psz_filename, "wt" );
     if( !p_export->p_file )
     {
         msg_Err( p_playlist , "could not create playlist file %s (%m)",
                  psz_filename );
+        free( p_export->psz_filename );
+        free( p_export );
         return VLC_EGENERIC;
     }
 
@@ -69,23 +69,27 @@ int playlist_Export( playlist_t * p_playlist, const char *psz_filename ,
     p_playlist->p_private = (void *)p_export;
 
     /* And call the module ! All work is done now */
-    p_module = module_Need( p_playlist, "playlist export", psz_type, true);
+    int i_ret;
+    p_module = module_need( p_playlist, "playlist export", psz_type, true);
     if( !p_module )
     {
         msg_Warn( p_playlist, "exporting playlist failed" );
-        vlc_object_unlock( p_playlist );
-        return VLC_ENOOBJ;
+        i_ret = VLC_ENOOBJ;
+    }
+    else
+    {
+        module_unneed( p_playlist , p_module );
+        i_ret = VLC_SUCCESS;
     }
-    module_Unneed( p_playlist , p_module );
 
     /* Clean up */
     fclose( p_export->p_file );
     free( p_export->psz_filename );
-    free ( p_export );
+    free( p_export );
     p_playlist->p_private = NULL;
     vlc_object_unlock( p_playlist );
 
-    return VLC_SUCCESS;
+    return i_ret;
 }
 
 /*****************************************************************************
@@ -160,7 +164,7 @@ int playlist_MLLoad( playlist_t *p_playlist )
     vlc_event_attach( &p_input->event_manager, vlc_InputItemSubItemAdded,
                         input_item_subitem_added, p_playlist );
 
-    p_playlist->b_doing_ml = true;
+    pl_priv(p_playlist)->b_doing_ml = true;
     PL_UNLOCK;
 
     stats_TimerStart( p_playlist, "ML Load", STATS_TIMER_ML_LOAD );
@@ -168,7 +172,7 @@ int playlist_MLLoad( playlist_t *p_playlist )
     stats_TimerStop( p_playlist,STATS_TIMER_ML_LOAD );
 
     PL_LOCK;
-    p_playlist->b_doing_ml = false;
+    pl_priv(p_playlist)->b_doing_ml = false;
     PL_UNLOCK;
 
     vlc_event_detach( &p_input->event_manager, vlc_InputItemSubItemAdded,