[vlc-devel] commit: LUA SD: simplify and fix a memory leak (untested) ( Rémi Denis-Courmont )
git version control
git at videolan.org
Thu Feb 4 19:37:10 CET 2010
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Feb 4 20:36:50 2010 +0200| [a9782f6334b1aacc56446833a7ab37159dbd72a0] | committer: Rémi Denis-Courmont
LUA SD: simplify and fix a memory leak (untested)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a9782f6334b1aacc56446833a7ab37159dbd72a0
---
modules/misc/lua/vlc.c | 68 +++++++++++++++++++-----------------------------
1 files changed, 27 insertions(+), 41 deletions(-)
diff --git a/modules/misc/lua/vlc.c b/modules/misc/lua/vlc.c
index 46997fa..25298be 100644
--- a/modules/misc/lua/vlc.c
+++ b/modules/misc/lua/vlc.c
@@ -196,69 +196,55 @@ int vlclua_scripts_batch_execute( vlc_object_t *p_this,
lua_State * L,
void * user_data)
{
- int i_ret = VLC_EGENERIC;
-
- char **ppsz_filelist = NULL;
- char **ppsz_fileend = NULL;
- char **ppsz_file;
-
char *ppsz_dir_list[] = { NULL, NULL, NULL, NULL };
- char **ppsz_dir;
- i_ret = vlclua_dir_list( p_this, luadirname, ppsz_dir_list );
+ int i_ret = vlclua_dir_list( p_this, luadirname, ppsz_dir_list );
if( i_ret != VLC_SUCCESS )
return i_ret;
i_ret = VLC_EGENERIC;
-
- for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
+ for( char **ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
{
+ char **ppsz_filelist;
int i_files;
- if( ppsz_filelist )
- {
- for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend;
- ppsz_file++ )
- free( *ppsz_file );
- free( ppsz_filelist );
- ppsz_filelist = NULL;
- }
-
msg_Dbg( p_this, "Trying Lua scripts in %s", *ppsz_dir );
i_files = utf8_scandir( *ppsz_dir, &ppsz_filelist, file_select,
file_compare );
- if( i_files < 1 ) continue;
- ppsz_fileend = ppsz_filelist + i_files;
+ if( i_files < 0 )
+ continue;
- for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend; ppsz_file++ )
+ char **ppsz_file = ppsz_filelist;
+ char **ppsz_fileend = ppsz_filelist + i_files;
+
+ while( ppsz_file < ppsz_fileend )
{
- char *psz_filename;
+ char *psz_filename;
+
if( asprintf( &psz_filename,
- "%s" DIR_SEP "%s", *ppsz_dir, *ppsz_file ) < 0)
+ "%s" DIR_SEP "%s", *ppsz_dir, *ppsz_file ) == -1 )
+ psz_filename = NULL;
+ free( *(ppsz_file++) );
+
+ if( likely(psz_filename != NULL) )
{
- vlclua_dir_list_free( ppsz_dir_list );
- return VLC_ENOMEM;
+ msg_Dbg( p_this, "Trying Lua playlist script %s",
+ psz_filename );
+ i_ret = func( p_this, psz_filename, L, user_data );
+ free( psz_filename );
+ if( i_ret == VLC_SUCCESS )
+ break;
}
- msg_Dbg( p_this, "Trying Lua playlist script %s", psz_filename );
-
- i_ret = func( p_this, psz_filename, L, user_data );
-
- free( psz_filename );
-
- if( i_ret == VLC_SUCCESS ) break;
}
- if( i_ret == VLC_SUCCESS ) break;
- }
- if( ppsz_filelist )
- {
- for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend;
- ppsz_file++ )
- free( *ppsz_file );
+ while( ppsz_file < ppsz_fileend )
+ free( *(ppsz_file++) );
free( ppsz_filelist );
+
+ if( i_ret == VLC_SUCCESS )
+ break;
}
vlclua_dir_list_free( ppsz_dir_list );
-
return i_ret;
}
More information about the vlc-devel
mailing list