+ /* Take the spin again. Note that another thread may have yielded the
+ * object in the (very short) mean time. */
+ vlc_spin_lock( &internals->ref_spin );
+ b_should_destroy = --internals->i_refcount == 0;
+ vlc_spin_unlock( &internals->ref_spin );
+
+ if( b_should_destroy )
+ {
+#ifndef NDEBUG
+ if( VLC_OBJECT(p_this->p_libvlc) == p_this )
+ {
+ /* Test for leaks */
+ vlc_object_t *leaked = internals->next;
+ while( leaked != p_this )
+ {
+ /* We are leaking this object */
+ fprintf( stderr,
+ "ERROR: leaking object (%p, type:%s, name:%s)\n",
+ leaked, leaked->psz_object_type,
+ leaked->psz_object_name );
+ /* Dump object to ease debugging */
+ vlc_object_dump( leaked );
+ fflush(stderr);
+ leaked = vlc_internals (leaked)->next;
+ }
+
+ if( internals->next != p_this )
+ /* Dump libvlc object to ease debugging */
+ vlc_object_dump( p_this );
+ }
+#endif
+ /* Remove the object from object list
+ * so that it cannot be encountered by vlc_object_get() */
+ vlc_internals (internals->next)->prev = internals->prev;
+ vlc_internals (internals->prev)->next = internals->next;
+
+ /* Detach from parent to protect against FIND_CHILDREN */
+ vlc_object_detach_unlocked (p_this);
+ /* Detach from children to protect against FIND_PARENT */
+ for (int i = 0; i < internals->i_children; i++)
+ internals->pp_children[i]->p_parent = NULL;
+ }
+