Commit a78e273e authored by Pierre d'Herbemont's avatar Pierre d'Herbemont
Browse files

misc/objects.c: Don't rely on vlc_object_destroy() to destroy objects, but...

misc/objects.c: Don't rely on vlc_object_destroy() to destroy objects, but expects vlc_object_release to do it when the refcount goes to zero.
* Meaning, that when created objects gets a refcount to 1.
* Destroying is instantaneous and we don't have to poll for a few secondss or so to wait until the object's refcount reach 0.
* We now track vlc_object_t's mem leaks when libvlc_global is released (Hard error for now, so they don't get unoticed)
* We fail hard if an object is released with a refcount of 1 without being detached from its parent and its children, to make sure such cases don't go unoticed.
(make test or make check still pass after that one. VLC is known to leak one object when no module is loaded, this must be fixed).
parent e769bca0
......@@ -232,7 +232,7 @@ static inline vlc_bool_t demux2_IsForced( demux_t *p_demux, const char *psz_name
module_Need( location, "packetizer", NULL, 0 ); \
if( location->p_module == NULL ) \
{ \
vlc_object_destroy( location ); \
vlc_object_release( location ); \
msg_Err( p_demux, "cannot find packetizer for " # msg ); \
free( p_sys ); \
return VLC_EGENERIC; \
......@@ -240,7 +240,7 @@ static inline vlc_bool_t demux2_IsForced( demux_t *p_demux, const char *psz_name
#define DESTROY_PACKETIZER( location ) \
if( location->p_module ) module_Unneed( location, location->p_module ); \
vlc_object_destroy( location );
vlc_object_release( location );
/**
* @}
......
......@@ -95,7 +95,6 @@ struct vlc_object_t
* Prototypes
*****************************************************************************/
VLC_EXPORT( void *, __vlc_object_create, ( vlc_object_t *, int ) );
VLC_EXPORT( void, __vlc_object_destroy, ( vlc_object_t * ) );
VLC_EXPORT( void, __vlc_object_attach, ( vlc_object_t *, vlc_object_t * ) );
VLC_EXPORT( void, __vlc_object_detach, ( vlc_object_t * ) );
VLC_EXPORT( void *, vlc_object_get, ( int ) );
......@@ -111,10 +110,6 @@ VLC_EXPORT( void, vlc_list_release, ( vlc_list_t * ) );
#define vlc_object_create(a,b) \
__vlc_object_create( VLC_OBJECT(a), b )
#define vlc_object_destroy(a) do { \
__vlc_object_destroy( VLC_OBJECT(a) ); \
(a) = NULL; } while(0)
#define vlc_object_detach(a) \
__vlc_object_detach( VLC_OBJECT(a) )
......
......@@ -271,7 +271,7 @@ static void Close( vlc_object_t *p_this )
p_sys->p_ev->pp_last = &p_sys->p_frame;
vlc_mutex_unlock( &p_sys->p_ev->lock );
}
vlc_object_destroy( p_sys->p_ev );
vlc_object_release( p_sys->p_ev );
}
if( p_sys->p_frame )
......
......@@ -357,7 +357,7 @@ static void Close( vlc_object_t *p_this )
/* stop the event handler */
vlc_object_kill( p_sys->p_ev );
vlc_thread_join( p_sys->p_ev );
vlc_object_destroy( p_sys->p_ev );
vlc_object_release( p_sys->p_ev );
var_Destroy( p_sys->p_input, "highlight-mutex" );
var_Destroy( p_sys->p_input, "highlight" );
......
......@@ -269,7 +269,7 @@ void *bonjour_start_service( vlc_object_t *p_log, const char *psz_stype,
error:
if( p_sys->poll_thread != NULL )
vlc_object_destroy( p_sys->poll_thread );
vlc_object_release( p_sys->poll_thread );
if( p_sys->client != NULL )
avahi_client_free( p_sys->client );
if( p_sys->simple_poll != NULL )
......@@ -295,7 +295,7 @@ void bonjour_stop_service( void *_p_sys )
vlc_object_kill( p_sys->poll_thread );
vlc_thread_join( p_sys->poll_thread );
vlc_object_destroy( p_sys->poll_thread );
vlc_object_release( p_sys->poll_thread );
if( p_sys->group != NULL )
avahi_entry_group_free( p_sys->group );
......
......@@ -232,7 +232,7 @@ static int Open( vlc_object_t *p_this )
if( i_handle == -1 )
{
msg_Err( p_access, "failed to create raw UDP socket" );
vlc_object_destroy (p_sys->p_thread);
vlc_object_release (p_sys->p_thread);
free (p_sys);
return VLC_EGENERIC;
}
......@@ -271,7 +271,7 @@ static int Open( vlc_object_t *p_this )
{
msg_Err( p_access->p_sout, "cannot spawn sout access thread" );
net_Close (i_handle);
vlc_object_destroy( p_sys->p_thread );
vlc_object_release( p_sys->p_thread );
free (p_sys);
return VLC_EGENERIC;
}
......@@ -316,7 +316,7 @@ static void Close( vlc_object_t * p_this )
net_Close( p_sys->p_thread->i_handle );
vlc_object_detach( p_sys->p_thread );
vlc_object_destroy( p_sys->p_thread );
vlc_object_release( p_sys->p_thread );
/* update p_sout->i_out_pace_nocontrol */
p_access->p_sout->i_out_pace_nocontrol--;
......
......@@ -374,7 +374,7 @@ static int OpenAudio( vlc_object_t *p_this )
{
msg_Err( p_aout, "cannot create DirectSoundThread" );
CloseHandle( p_aout->output.p_sys->p_notif->event );
vlc_object_destroy( p_aout->output.p_sys->p_notif );
vlc_object_release( p_aout->output.p_sys->p_notif );
p_aout->output.p_sys->p_notif = NULL;
goto error;
}
......@@ -594,7 +594,7 @@ static void CloseAudio( vlc_object_t *p_this )
if( !p_sys->b_playing ) SetEvent( p_sys->p_notif->event );
vlc_thread_join( p_sys->p_notif );
vlc_object_destroy( p_sys->p_notif );
vlc_object_release( p_sys->p_notif );
}
/* release the secondary buffer */
......
......@@ -495,7 +495,7 @@ static void Close( vlc_object_t *p_this )
/* wake up the audio thread */
SetEvent( p_sys->event );
vlc_thread_join( p_sys->p_notif );
vlc_object_destroy( p_sys->p_notif );
vlc_object_release( p_sys->p_notif );
CloseHandle( p_sys->event );
/* Close the device */
......
......@@ -300,7 +300,7 @@ int E_(OpenChroma)( vlc_object_t *p_this )
if( !p_sys->p_swscaler->p_module || !p_sys->p_swscaler->p_owner )
{
vlc_object_detach( p_sys->p_swscaler );
vlc_object_destroy( p_sys->p_swscaler );
vlc_object_release( p_sys->p_swscaler );
free( p_vout->chroma.p_sys );
return VLC_EGENERIC;
}
......@@ -355,7 +355,7 @@ void E_(CloseChroma)( vlc_object_t *p_this )
free( p_sys->p_swscaler->p_owner );
module_Unneed( p_sys->p_swscaler, p_sys->p_swscaler->p_module );
vlc_object_detach( p_sys->p_swscaler );
vlc_object_destroy( p_sys->p_swscaler );
vlc_object_release( p_sys->p_swscaler );
p_sys->p_swscaler= NULL;
}
free( p_vout->chroma.p_sys );
......
......@@ -1036,7 +1036,7 @@ void E_(CloseEncoder)( vlc_object_t *p_this )
vlc_thread_join( pp_contexts[i] );
vlc_mutex_destroy( &pp_contexts[i]->lock );
vlc_cond_destroy( &pp_contexts[i]->cond );
vlc_object_destroy( pp_contexts[i] );
vlc_object_release( pp_contexts[i] );
}
free( pp_contexts );
......
......@@ -152,7 +152,7 @@ static int Open( vlc_object_t * p_this )
{
if( p_sys->p_packetizer->fmt_in.p_extra )
free( p_sys->p_packetizer->fmt_in.p_extra );
vlc_object_destroy( p_sys->p_packetizer );
vlc_object_release( p_sys->p_packetizer );
msg_Err( p_demux, "cannot find flac packetizer" );
return VLC_EGENERIC;
......@@ -193,7 +193,7 @@ static void Close( vlc_object_t * p_this )
free( p_sys->p_packetizer->fmt_in.p_extra );
/* Delete the decoder */
vlc_object_destroy( p_sys->p_packetizer );
vlc_object_release( p_sys->p_packetizer );
if( p_sys->p_meta )
vlc_meta_Delete( p_sys->p_meta );
free( p_sys );
......
......@@ -398,7 +398,7 @@ error:
vlc_object_kill( p_sys->p_timeout );
vlc_thread_join( p_sys->p_timeout );
vlc_object_detach( p_sys->p_timeout );
vlc_object_destroy( p_sys->p_timeout );
vlc_object_release( p_sys->p_timeout );
}
if( p_sys->scheduler ) delete p_sys->scheduler;
if( p_sys->p_sdp ) free( p_sys->p_sdp );
......@@ -439,7 +439,7 @@ static void Close( vlc_object_t *p_this )
vlc_object_kill( p_sys->p_timeout );
vlc_thread_join( p_sys->p_timeout );
vlc_object_detach( p_sys->p_timeout );
vlc_object_destroy( p_sys->p_timeout );
vlc_object_release( p_sys->p_timeout );
}
if( p_sys->scheduler ) delete p_sys->scheduler;
if( p_sys->p_sdp ) free( p_sys->p_sdp );
......@@ -1033,7 +1033,7 @@ static int Play( demux_t *p_demux )
VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
{
msg_Err( p_demux, "cannot spawn liveMedia timeout thread" );
vlc_object_destroy( p_sys->p_timeout );
vlc_object_release( p_sys->p_timeout );
}
msg_Dbg( p_demux, "spawned timeout thread" );
vlc_object_attach( p_sys->p_timeout, p_demux );
......
......@@ -2693,7 +2693,7 @@ void demux_sys_t::StopUiThread()
{
vlc_object_kill( p_ev );
vlc_thread_join( p_ev );
vlc_object_destroy( p_ev );
vlc_object_release( p_ev );
p_ev = NULL;
......
......@@ -546,7 +546,7 @@ static void CloseBlending( intf_thread_t *p_intf )
p_intf->p_sys->p_blend->p_module );
vlc_object_detach( p_intf->p_sys->p_blend );
vlc_object_destroy( p_intf->p_sys->p_blend );
vlc_object_release( p_intf->p_sys->p_blend );
}
}
#endif
......@@ -597,7 +597,7 @@ static void CloseTextRenderer( intf_thread_t *p_intf )
p_intf->p_sys->p_text->p_module );
vlc_object_detach( p_intf->p_sys->p_text );
vlc_object_destroy( p_intf->p_sys->p_text );
vlc_object_release( p_intf->p_sys->p_text );
}
}
#if 0
......@@ -636,7 +636,7 @@ static int CloseScaling( intf_thread_t *p_intf )
p_intf->p_sys->p_scale->p_module );
vlc_object_detach( p_intf->p_sys->p_scale );
vlc_object_destroy( p_intf->p_sys->p_scale );
vlc_object_release( p_intf->p_sys->p_scale );
}
}
#endif
......
......@@ -116,7 +116,7 @@ Dialogs::~Dialogs()
vlc_object_detach( m_pProvider );
module_Unneed( m_pProvider, m_pModule );
vlc_object_destroy( m_pProvider );
vlc_object_release( m_pProvider );
}
/* Unregister callbacks */
......@@ -170,7 +170,7 @@ bool Dialogs::init()
if( m_pModule == NULL )
{
msg_Err( getIntf(), "no suitable dialogs provider found (hint: compile the wxWidgets plugin, and make sure it is loaded properly)" );
vlc_object_destroy( m_pProvider );
vlc_object_release( m_pProvider );
m_pProvider = NULL;
return false;
}
......
......@@ -249,7 +249,7 @@ static void Unload( intf_thread_t *p_this )
if( p_this->p_module )
module_Unneed( p_this, p_this->p_module );
vlc_mutex_destroy( &p_this->change_lock );
vlc_object_destroy( p_this );
vlc_object_release( p_this );
}
/*****************************************************************************
......
......@@ -408,7 +408,7 @@ static int Create( vlc_object_t *p_this )
}
else
{
vlc_object_destroy( p_fontbuilder );
vlc_object_release( p_fontbuilder );
}
}
else
......
......@@ -936,7 +936,7 @@ gnutls_SessionClose (tls_server_t *p_server, tls_session_t *p_session)
gnutls_deinit( p_sys->session );
vlc_object_detach( p_session );
vlc_object_destroy( p_session );
vlc_object_release( p_session );
free( p_sys );
}
......@@ -960,7 +960,7 @@ gnutls_ServerSessionPrepare( tls_server_t *p_server )
p_session->p_sys = malloc( sizeof(struct tls_session_sys_t) );
if( p_session->p_sys == NULL )
{
vlc_object_destroy( p_session );
vlc_object_release( p_session );
return NULL;
}
......@@ -1016,7 +1016,7 @@ gnutls_ServerSessionPrepare( tls_server_t *p_server )
error:
free( p_session->p_sys );
vlc_object_detach( p_session );
vlc_object_destroy( p_session );
vlc_object_release( p_session );
return NULL;
}
......
......@@ -111,7 +111,7 @@ static int Open( vlc_object_t *p_this )
if( vlc_thread_create( p_gtk_main, "gtk_main", GtkMain,
VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
{
vlc_object_destroy( p_gtk_main );
vlc_object_release( p_gtk_main );
i_refcount--;
vlc_mutex_unlock( lock );
return VLC_ETHREAD;
......@@ -143,7 +143,7 @@ static void Close( vlc_object_t *p_this )
gtk_main_quit();
vlc_thread_join( p_gtk_main );
vlc_object_destroy( p_gtk_main );
vlc_object_release( p_gtk_main );
p_gtk_main = NULL;
vlc_mutex_unlock( lock );
......
......@@ -105,7 +105,7 @@ static int Open( vlc_object_t *p_this )
if( vlc_thread_create( p_qte_main, "qte_main", QteMain,
VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
{
vlc_object_destroy( p_qte_main );
vlc_object_release( p_qte_main );
i_refcount--;
vlc_mutex_unlock( lock );
return VLC_ETHREAD;
......@@ -145,7 +145,7 @@ static void Close( vlc_object_t *p_this )
msg_Dbg( p_this, "Detaching qte_main" );
vlc_object_detach( p_qte_main );
vlc_object_destroy( p_qte_main );
vlc_object_release( p_qte_main );
p_qte_main = NULL;
vlc_mutex_unlock( lock );
......
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