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

LUA: fix memory leaks in error path

parent c7eabcd9
...@@ -150,42 +150,35 @@ static int file_compare( const char **a, const char **b ) ...@@ -150,42 +150,35 @@ static int file_compare( const char **a, const char **b )
return strcmp( *a, *b ); return strcmp( *a, *b );
} }
int vlclua_dir_list( vlc_object_t *p_this, const char *luadirname, char **ppsz_dir_list ) int vlclua_dir_list( vlc_object_t *p_this, const char *luadirname,
char **ppsz_dir_list )
{ {
int i = 0; int i = 0;
char *datadir = config_GetUserDir( VLC_DATA_DIR ); char *datadir = config_GetUserDir( VLC_DATA_DIR );
if( datadir == NULL )
return VLC_ENOMEM;
if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "lua" DIR_SEP "%s", if( likely(datadir != NULL)
datadir, luadirname ) < 0 ) && likely(asprintf( &ppsz_dir_list[i], "%s"DIR_SEP"lua"DIR_SEP"%s",
{ datadir, luadirname ) != -1) )
free( datadir );
return VLC_ENOMEM;
}
free( datadir );
i++; i++;
free( datadir );
char *psz_datapath = config_GetDataDir( p_this ); char *psz_datapath = config_GetDataDir( p_this );
# if defined(__APPLE__) || defined(SYS_BEOS) || defined(WIN32) if( likely(psz_datapath != NULL) )
{ {
if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "lua" DIR_SEP "%s", if( likely(asprintf( &ppsz_dir_list[i], "%s"DIR_SEP"lua"DIR_SEP"%s",
psz_datapath, luadirname ) < 0 ) psz_datapath, luadirname ) != -1) )
return VLC_ENOMEM;
i++;
if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "share" DIR_SEP "lua" DIR_SEP "%s",
psz_datapath, luadirname ) < 0 )
return VLC_ENOMEM;
i++; i++;
} #if defined(__APPLE__) || defined(SYS_BEOS) || defined(WIN32)
# else if( likely(asprintf( &ppsz_dir_list[i],
if( asprintf( &ppsz_dir_list[i], "%s" DIR_SEP "lua" DIR_SEP "%s", "%s"DIR_SEP"share"DIR_SEP"lua"DIR_SEP"%s",
psz_datapath, luadirname ) < 0 ) psz_datapath, luadirname ) != -1) )
return VLC_ENOMEM;
i++; i++;
# endif #endif
free( psz_datapath ); free( psz_datapath );
}
ppsz_dir_list[i] = NULL;
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
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