[vlc-devel] commit: Fix resource leak when loadsave fail (CID 94) ( Rémi Duraffort )

git version control git at videolan.org
Mon Oct 6 15:46:46 CEST 2008


vlc | branch: 0.9-bugfix | Rémi Duraffort <ivoire at videolan.org> | Sun Oct  5 18:11:50 2008 +0200| [76bbe6a62aee35adf7d82a3199bfdee3a17580de] | committer: Derk-Jan Hartman 

Fix resource leak when loadsave fail (CID 94)

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

 src/playlist/loadsave.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/playlist/loadsave.c b/src/playlist/loadsave.c
index 4c56c36..0a211b6 100644
--- a/src/playlist/loadsave.c
+++ b/src/playlist/loadsave.c
@@ -51,14 +51,14 @@ int playlist_Export( playlist_t * p_playlist, const char *psz_filename ,
     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;
 }
 
 /*****************************************************************************




More information about the vlc-devel mailing list