[vlc-devel] [PATCH] libvlc: dump object names that are leaking
Thomas Guillem
thomas at gllm.fr
Thu Jun 8 09:02:55 CEST 2017
On Wed, Jun 7, 2017, at 19:23, David Fuhrmann wrote:
>
> > 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.
Indeed, there is no leak sanitizer on macPs (there is asan but without
the leak feature).
It's always possible to attach a debugger and navigate through the list
of objects, but this is not as convenient as having the objects
displayed directly when the program crash. Furthermore, you can't attach
a debugger on every devices, there is some hardware constructors on
Android (like Samsung) that prevent to attach gdb to a process.
>
> BR. David
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list