[vlc-commits] [Git][videolan/vlc][master] 2 commits: codec: webvtt: fix recursive cleanup

François Cartegnie (@fcartegnie) gitlab at videolan.org
Sat Nov 1 15:01:02 UTC 2025



François Cartegnie pushed to branch master at VideoLAN / VLC


Commits:
73861536 by François Cartegnie at 2025-11-01T15:46:30+01:00
codec: webvtt: fix recursive cleanup

no siblings were reclaimed on cleanup

regression by 150a7f5648970abfe9adfa84586d951ec4951645

- - - - -
5902316a by François Cartegnie at 2025-11-01T15:46:30+01:00
codec: webvtt: replace recursive css cleanup

refs #29392

- - - - -


1 changed file:

- modules/codec/webvtt/subsvtt.c


Changes:

=====================================
modules/codec/webvtt/subsvtt.c
=====================================
@@ -456,16 +456,14 @@ static void webvtt_domnode_AppendLast( webvtt_dom_node_t **pp_append,
     webvtt_domnode_AppendLast( (webvtt_dom_node_t **) a, (webvtt_dom_node_t *) b )
 
 
-static webvtt_dom_node_t *webvtt_domnode_DeleteNode( webvtt_dom_node_t *p_node )
+static void webvtt_domnode_DeleteNode( webvtt_dom_node_t *p_node )
 {
-    webvtt_dom_node_t *p_child = NULL;
     if( p_node->type == NODE_TAG )
     {
         webvtt_dom_tag_t *p_tag_node = (webvtt_dom_tag_t *) p_node;
         text_style_Delete( p_tag_node->p_cssstyle );
         free( p_tag_node->psz_attrs );
         free( p_tag_node->psz_tag );
-        p_child = p_tag_node->p_child;
     }
     else if( p_node->type == NODE_TEXT )
     {
@@ -478,30 +476,51 @@ static webvtt_dom_node_t *webvtt_domnode_DeleteNode( webvtt_dom_node_t *p_node )
         text_style_Delete( p_cue_node->p_cssstyle );
         webvtt_cue_settings_Clean( &p_cue_node->settings );
         free( p_cue_node->psz_id );
-        p_child = p_cue_node->p_child;
     }
     else if( p_node->type == NODE_REGION )
     {
         webvtt_region_t *p_region_node = (webvtt_region_t *)p_node;
         text_style_Delete( p_region_node->p_cssstyle );
         free( p_region_node->psz_id );
-        p_child = p_region_node->p_child;
     }
     free( p_node );
-    return p_child;
 }
 
+static webvtt_dom_node_t * webvtt_domnode_getFirstChild( webvtt_dom_node_t *p_node );
+
 static void webvtt_domnode_ChainDelete( webvtt_dom_node_t *p_node )
 {
+    vlc_array_t stack;
+    vlc_array_init( &stack );
+
     while( p_node )
     {
+        webvtt_dom_node_t *p_child = webvtt_domnode_getFirstChild( p_node );
         webvtt_dom_node_t *p_next = p_node->p_next;
-        webvtt_dom_node_t *p_child = webvtt_domnode_DeleteNode( p_node );
-        while ( p_child )
-            p_child = webvtt_domnode_DeleteNode( p_child );
+        /* delete current node, then go to child, and then siblings */
+        webvtt_domnode_DeleteNode( p_node );
+        p_node = p_child;
+        if( p_next )
+        {
+            if( p_child ) /* go to child, process sibling later */
+                vlc_array_append( &stack, p_next );
+            else
+                p_node = p_next;
+        }
 
-        p_node = p_next;
+        if( !p_node )
+        {
+            /* pop saved next node */
+            size_t idx = vlc_array_count( &stack );
+            if( idx )
+            {
+                p_node = vlc_array_item_at_index( &stack, idx - 1 );
+                vlc_array_remove( &stack, idx - 1 );
+            }
+        }
     }
+
+    vlc_array_clear( &stack );
 }
 
 static webvtt_dom_text_t * webvtt_dom_text_New( webvtt_dom_node_t *p_parent )
@@ -1738,9 +1757,46 @@ static void ClearCSSStyles( webvtt_dom_node_t *p_node )
 {
     if( webvtt_domnode_supportsCSSStyle( p_node ) )
         webvtt_domnode_setCSSStyle( p_node, NULL );
-    webvtt_dom_node_t *p_child = webvtt_domnode_getFirstChild( p_node );
-    for ( ; p_child ; p_child = p_child->p_next )
-        ClearCSSStyles( p_child );
+
+    /* start from leaves */
+    p_node = webvtt_domnode_getFirstChild( p_node );
+    if( !p_node )
+        return;
+
+    vlc_array_t stack;
+    vlc_array_init( &stack );
+
+    while( p_node )
+    {
+        if( webvtt_domnode_supportsCSSStyle( p_node ) )
+            webvtt_domnode_setCSSStyle( p_node, NULL );
+
+        webvtt_dom_node_t *p_child = webvtt_domnode_getFirstChild( p_node );
+        if( p_child ) /* explore first */
+        {
+            if( p_node->p_next )
+                vlc_array_append( &stack, p_node->p_next );
+            p_node = p_child;
+        }
+        else
+        {
+            p_node = p_node->p_next;
+
+            if( !p_node )
+            {
+                /* continue on parent sibling */
+                size_t idx = vlc_array_count( &stack );
+                if( idx )
+                {
+                    p_node = vlc_array_item_at_index( &stack, idx - 1 );
+                    vlc_array_remove( &stack, idx - 1 );
+                    p_node = p_node->p_next;
+                }
+            }
+        }
+    }
+
+    vlc_array_clear( &stack );
 }
 
 #ifdef HAVE_CSS



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/81cda618161bdb7dab6e66d9d7f751b3777e2efc...5902316a43d47cda218330f94756286659756d55

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/81cda618161bdb7dab6e66d9d7f751b3777e2efc...5902316a43d47cda218330f94756286659756d55
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list