Commit a9782f63 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

LUA SD: simplify and fix a memory leak (untested)

parent 4550f048
...@@ -196,69 +196,55 @@ int vlclua_scripts_batch_execute( vlc_object_t *p_this, ...@@ -196,69 +196,55 @@ int vlclua_scripts_batch_execute( vlc_object_t *p_this,
lua_State * L, lua_State * L,
void * user_data) 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_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 ) if( i_ret != VLC_SUCCESS )
return i_ret; return i_ret;
i_ret = VLC_EGENERIC; i_ret = VLC_EGENERIC;
for( char **ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
{ {
char **ppsz_filelist;
int i_files; 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 ); msg_Dbg( p_this, "Trying Lua scripts in %s", *ppsz_dir );
i_files = utf8_scandir( *ppsz_dir, &ppsz_filelist, file_select, i_files = utf8_scandir( *ppsz_dir, &ppsz_filelist, file_select,
file_compare ); file_compare );
if( i_files < 1 ) continue; if( i_files < 0 )
ppsz_fileend = ppsz_filelist + i_files; 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, 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;
vlclua_dir_list_free( ppsz_dir_list ); free( *(ppsz_file++) );
return VLC_ENOMEM;
}
msg_Dbg( p_this, "Trying Lua playlist script %s", psz_filename );
if( likely(psz_filename != NULL) )
{
msg_Dbg( p_this, "Trying Lua playlist script %s",
psz_filename );
i_ret = func( p_this, psz_filename, L, user_data ); i_ret = func( p_this, psz_filename, L, user_data );
free( psz_filename ); free( psz_filename );
if( i_ret == VLC_SUCCESS )
if( i_ret == VLC_SUCCESS ) break; break;
} }
if( i_ret == VLC_SUCCESS ) break;
} }
if( ppsz_filelist ) while( ppsz_file < ppsz_fileend )
{ free( *(ppsz_file++) );
for( ppsz_file = ppsz_filelist; ppsz_file < ppsz_fileend;
ppsz_file++ )
free( *ppsz_file );
free( ppsz_filelist ); free( ppsz_filelist );
if( i_ret == VLC_SUCCESS )
break;
} }
vlclua_dir_list_free( ppsz_dir_list ); vlclua_dir_list_free( ppsz_dir_list );
return i_ret; return i_ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment