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,
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;
}
......
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