[vlc-devel] [PATCH] libvlc: dump object names that are leaking

David Fuhrmann david.fuhrmann at gmail.com
Wed Jun 7 19:23:50 CEST 2017


> Am 07.06.2017 um 11:34 schrieb Thomas Guillem <thomas at gllm.fr>:
> 
> In case of a vlc_object_t leak, and if asserts are enabled, the error output
> will be like the following:
> 
> === vlc_object LEAKS detected ===
>  | art finder
>  | meta fetcher
>  | input
>  |   \ input source
>  |   |   \ demux meta
>  |   |   | demux
>  |   |   | stream
>  |   |   |   \ stream
> ---
> src/libvlc.c | 28 ++++++++++++++++++++++++++++
> 1 file changed, 28 insertions(+)
> 
> diff --git a/src/libvlc.c b/src/libvlc.c
> index 4b220d2e31..45b0dd14d1 100644
> --- a/src/libvlc.c
> +++ b/src/libvlc.c
> @@ -554,6 +554,22 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
> #endif
> }
> 
> +#ifndef NDEBUG
> +static void DumpObjectLeaks(vlc_object_internals_t *priv, unsigned level)
> +{
> +    bool first = true;
> +    for (priv = priv->first; priv != NULL;  priv = priv->next)
> +    {
> +        vlc_object_t *obj = vlc_externals(priv);
> +        for( unsigned i = 0; i < level; i++ )
> +            fprintf( stderr, "  %s ", first && i == level -1 ? "\\" : "|" );
> +        fprintf( stderr, "%s\n", obj->obj.object_type );
> +        DumpObjectLeaks( priv, level + 1 );
> +        first = false;
> +    }
> +}
> +#endif
> +
> /**
>  * Destroy everything.
>  * This function requests the running threads to finish, waits for their
> @@ -567,6 +583,18 @@ void libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
> 
>     vlc_ExitDestroy( &priv->exit );
> 
> +#ifndef NDEBUG
> +    {
> +        vlc_object_internals_t *priv = vlc_internals(p_libvlc);
> +        if( atomic_load( &priv->refs ) != 1 )
> +        {
> +            vlc_mutex_lock( &priv->tree_lock );
> +            fprintf( stderr, "=== vlc_object LEAKS detected ===\n" );
> +            DumpObjectLeaks( priv, 1 );
> +            vlc_mutex_unlock( &priv->tree_lock );
> +        }
> +    }
> +#endif
>     assert( atomic_load(&(vlc_internals(p_libvlc)->refs)) == 1 );
>     vlc_object_release( p_libvlc );
> }
> -- 

Hi,

I would find such an addition quite helpful. Getting the information from a debugger was very complex last time I tried.
So I would say add this as an additional helper.

BR. David


More information about the vlc-devel mailing list