1
mirror of https://code.videolan.org/videolan/vlc synced 2024-10-03 01:31:53 +02:00

SD: initialize config chain also in LibVLC media discovery, fix leaks

This commit is contained in:
Rémi Denis-Courmont 2010-02-04 18:50:08 +02:00
parent 711d150666
commit 6e160dae0f
4 changed files with 31 additions and 24 deletions

View File

@ -48,6 +48,7 @@ struct services_discovery_t
vlc_event_manager_t event_manager; /* Accessed through Setters for non class function */
char *psz_name;
config_chain_t *p_cfg;
services_discovery_sys_t *p_sys;
@ -64,14 +65,10 @@ VLC_EXPORT( char **, vlc_sd_GetNames, ( vlc_object_t *, char *** ) );
vlc_sd_GetNames(VLC_OBJECT(obj), pln)
/* Creation of a service_discovery object */
VLC_EXPORT( services_discovery_t *, vlc_sd_Create, ( vlc_object_t * ) );
VLC_EXPORT( bool, vlc_sd_Start, ( services_discovery_t *, const char * ) );
VLC_EXPORT( services_discovery_t *, vlc_sd_Create, ( vlc_object_t *, const char * ) );
VLC_EXPORT( bool, vlc_sd_Start, ( services_discovery_t * ) );
VLC_EXPORT( void, vlc_sd_Stop, ( services_discovery_t * ) );
static inline void vlc_sd_Destroy( services_discovery_t *p_sd )
{
vlc_object_release( VLC_OBJECT(p_sd) );
}
VLC_EXPORT( void, vlc_sd_Destroy, ( services_discovery_t * ) );
static inline void vlc_sd_StopAndDestroy( services_discovery_t * p_this )
{

View File

@ -199,9 +199,9 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
libvlc_event_manager_register_event_type( p_mdis->p_event_manager,
libvlc_MediaDiscovererEnded );
p_mdis->p_sd = vlc_sd_Create( (vlc_object_t*)p_inst->p_libvlc_int );
if( !p_mdis->p_sd )
p_mdis->p_sd = vlc_sd_Create( (vlc_object_t*)p_inst->p_libvlc_int,
psz_name );
if( unlikely(p_mdis->p_sd == NULL) )
{
libvlc_printerr( "%s: no such discovery module found", psz_name );
libvlc_media_list_release( p_mdis->p_mlist );
@ -228,9 +228,10 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
p_mdis );
/* Here we go */
if( !vlc_sd_Start( p_mdis->p_sd, psz_name ) )
if( !vlc_sd_Start( p_mdis->p_sd ) )
{
libvlc_printerr( "%s: internal module error", psz_name );
libvlc_printerr( "%s: internal module error",
p_mdis->p_sd->psz_name );
libvlc_media_list_release( p_mdis->p_mlist );
libvlc_event_manager_release( p_mdis->p_event_manager );
free( p_mdis );

View File

@ -557,6 +557,7 @@ vlc_rwlock_unlock
vlc_rwlock_wrlock
vlc_savecancel
vlc_sd_Create
vlc_sd_Destroy
vlc_sd_GetNames
vlc_sd_probe_Add
vlc_sdp_Start

View File

@ -107,7 +107,8 @@ static void services_discovery_Destructor ( vlc_object_t *p_obj );
/***********************************************************************
* Create
***********************************************************************/
services_discovery_t *vlc_sd_Create( vlc_object_t *p_super )
services_discovery_t *vlc_sd_Create( vlc_object_t *p_super,
const char *cfg )
{
services_discovery_t *p_sd;
@ -115,6 +116,7 @@ services_discovery_t *vlc_sd_Create( vlc_object_t *p_super )
"services discovery" );
if( !p_sd )
return NULL;
free(config_ChainCreate( &p_sd->psz_name, &p_sd->p_cfg, cfg ));
vlc_event_manager_init( &p_sd->event_manager, p_sd, (vlc_object_t *)p_sd );
vlc_event_manager_register_event_type( &p_sd->event_manager,
@ -135,12 +137,12 @@ services_discovery_t *vlc_sd_Create( vlc_object_t *p_super )
/***********************************************************************
* Stop
***********************************************************************/
bool vlc_sd_Start ( services_discovery_t * p_sd, const char *module )
bool vlc_sd_Start ( services_discovery_t * p_sd )
{
assert(!p_sd->p_module);
p_sd->p_module = module_need( p_sd, "services_discovery", module, true );
p_sd->p_module = module_need( p_sd, "services_discovery",
p_sd->psz_name, true );
if( p_sd->p_module == NULL )
{
msg_Err( p_sd, "no suitable services discovery module" );
@ -169,6 +171,13 @@ void vlc_sd_Stop ( services_discovery_t * p_sd )
p_sd->p_module = NULL;
}
void vlc_sd_Destroy( services_discovery_t *p_sd )
{
config_ChainDestroy( p_sd->p_cfg );
free( p_sd->psz_name );
vlc_object_release( p_sd );
}
/***********************************************************************
* Destructor
***********************************************************************/
@ -271,18 +280,17 @@ static void playlist_sd_item_removed( const vlc_event_t * p_event, void * user_d
playlist_DeleteFromInput( p_parent->p_playlist, p_input, false );
}
int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_module )
int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist,
const char *psz_name )
{
/* Perform the addition */
msg_Dbg( p_playlist, "adding services_discovery %s...", psz_module );
services_discovery_t *p_sd;
services_discovery_t *p_sd = vlc_sd_Create( VLC_OBJECT(p_playlist) );
msg_Dbg( p_playlist, "adding services_discovery %s...", psz_name );
p_sd = vlc_sd_Create( VLC_OBJECT(p_playlist), psz_name );
if( !p_sd )
return VLC_ENOMEM;
char *psz_name = NULL;
config_ChainCreate( &psz_name, &p_sd->p_cfg, psz_module );
module_t *m = module_find_by_shortcut( psz_name );
if( !m )
{
@ -316,7 +324,7 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modul
vlc_ServicesDiscoveryItemRemoved,
playlist_sd_item_removed, p_node );
if( !vlc_sd_Start( p_sd, psz_name ) )
if( !vlc_sd_Start( p_sd ) )
{
vlc_sd_Destroy( p_sd );
free( p_sds );
@ -327,7 +335,7 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modul
p_node->p_input->b_prefers_tree = true;
p_sds->p_sd = p_sd;
p_sds->p_node = p_node;
p_sds->psz_name = strdup( psz_module );
p_sds->psz_name = strdup( psz_name );
PL_LOCK;
TAB_APPEND( pl_priv(p_playlist)->i_sds, pl_priv(p_playlist)->pp_sds, p_sds );