- if( b_should_destroy )
- {
- /* Remove the object from the table so that it cannot be returned from
- * vlc_object_find() and friends. */
- libvlc_global_data_t *p_libvlc_global = vlc_global();
- int i_index;
-
- i_index = FindIndex( p_this, p_libvlc_global->pp_objects,
- p_libvlc_global->i_objects );
- REMOVE_ELEM( p_libvlc_global->pp_objects,
- p_libvlc_global->i_objects, i_index );
- if (p_this->p_parent)
- vlc_object_detach_unlocked (p_this);
- }
+ /* Remove the object from the table
+ * so that it cannot be encountered by vlc_object_get() */
+ libvlc_global_data_t *p_libvlc_global = vlc_global();
+ int i_index;
+
+ i_index = FindIndex( p_this, p_libvlc_global->pp_objects,
+ p_libvlc_global->i_objects );
+ REMOVE_ELEM( p_libvlc_global->pp_objects,
+ p_libvlc_global->i_objects, i_index );
+
+ /* Detach from parent to protect against FIND_CHILDREN */
+ if (p_this->p_parent)
+ vlc_object_detach_unlocked (p_this);
+ /* Detach from children to protect against FIND_PARENT */
+ for (int i = 0; i < p_this->i_children; i++)
+ p_this->pp_children[i]->p_parent = NULL;