[vlc-devel] [PATCH] libvlc: dump object names that are leaking
Thomas Guillem
thomas at gllm.fr
Wed Jun 7 11:34:13 CEST 2017
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 );
}
--
2.11.0
More information about the vlc-devel
mailing list