[vlc-commits] [Git][videolan/vlc][master] Lua : replace recursive logic with iterative approach

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Apr 12 10:28:51 UTC 2025



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
33e05c84 by Kartik Dua at 2025-04-12T10:12:56+00:00
Lua : replace recursive logic with iterative approach

Converted recursive implementation to an iterative one to prevent
stack overflows from deeply nested calls. This enhances stability
and ensures safer execution for long sequences.

- - - - -


1 changed file:

- modules/lua/extension_thread.c


Changes:

=====================================
modules/lua/extension_thread.c
=====================================
@@ -146,28 +146,27 @@ error_listener:
     return VLC_ENOMEM;
 }
 
-/** Recursively drop and free commands starting from "command" */
 static void FreeCommands( struct command_t *command )
 {
-    if( !command ) return;
-    struct command_t *next = command->next;
-    switch( command->i_command )
-    {
-        case CMD_ACTIVATE:
-        case CMD_DEACTIVATE:
-        case CMD_CLICK: // Arg1 must not be freed
-            break;
-
-        case CMD_TRIGGERMENU:
-        case CMD_PLAYING_CHANGED:
-            free( command->data[0] ); // Arg1 is int*, to free
-            break;
-
-        default:
-            break;
+    while (command) {
+        struct command_t *next = command->next;
+        switch( command->i_command )
+        {
+            case CMD_ACTIVATE:
+            case CMD_DEACTIVATE:
+            case CMD_CLICK:
+                /* No extra memory to free */
+                break;
+            case CMD_TRIGGERMENU:
+            case CMD_PLAYING_CHANGED:
+                free( command->data[0] ); // free allocated data
+                break;
+            default:
+                break;
+        }
+        free(command);
+        command = next;
     }
-    free( command );
-    FreeCommands( next );
 }
 
 bool QueueDeactivateCommand( extension_t *p_ext )



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/33e05c8474f431fe735826961e89b38b9f4e3664

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/33e05c8474f431fe735826961e89b38b9f4e3664
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