[vlc-commits] lua: remove spurious strdup ( a string is valid as long as it stays on the stack)

Rémi Duraffort git at videolan.org
Sat Jun 18 00:15:59 CEST 2011


vlc | branch: master | Rémi Duraffort <ivoire at videolan.org> | Fri Jun 17 23:26:57 2011 +0200| [89593593021d596f31e2786b47d4ff5ca08a6abe] | committer: Rémi Duraffort

lua: remove spurious strdup (a string is valid as long as it stays on the stack)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=89593593021d596f31e2786b47d4ff5ca08a6abe
---

 modules/lua/libs/sd.c |   28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/modules/lua/libs/sd.c b/modules/lua/libs/sd.c
index cc91076..288c27d 100644
--- a/modules/lua/libs/sd.c
+++ b/modules/lua/libs/sd.c
@@ -114,12 +114,13 @@ static int vlclua_sd_add_node( lua_State *L )
         lua_getfield( L, -1, "title" );
         if( lua_isstring( L, -1 ) )
         {
-            char *name = strdup( lua_tostring( L, -1 ) );
-            lua_pop( L, 1 );
+            const char *psz_name = lua_tostring( L, -1 );
             input_item_t *p_input = input_item_NewWithType( VLC_OBJECT( p_sd ),
                                                             "vlc://nop",
-                                                            name, 0, NULL, 0,
+                                                            psz_name, 0, NULL, 0,
                                                             -1, ITEM_TYPE_NODE );
+            lua_pop( L, 1 );
+
             if( p_input )
             {
                 lua_getfield( L, -1, "arturl" );
@@ -144,7 +145,6 @@ static int vlclua_sd_add_node( lua_State *L )
                 }
                 lua_setmetatable( L, -2 );
             }
-            free( name );
         }
         else
             msg_Err( p_sd, "vlc.sd.add_node: the \"title\" parameter can't be empty" );
@@ -164,13 +164,14 @@ static int vlclua_sd_add_item( lua_State *L )
         {
             char **ppsz_options = NULL;
             int i_options = 0;
-            char *psz_path = strdup( lua_tostring( L, -1 ) );
-            lua_pop( L, 1 );
+            const char *psz_path = lua_tostring( L, -1 );
             vlclua_read_options( p_sd, L, &i_options, &ppsz_options );
             input_item_t *p_input = input_item_NewExt( p_sd, psz_path, psz_path,
                                                        i_options,
                                                        (const char **)ppsz_options,
                                                        VLC_INPUT_OPTION_TRUSTED, -1 );
+            lua_pop( L, 1 );
+
             if( p_input )
             {
                 vlclua_read_meta_data( p_sd, L, p_input );
@@ -195,7 +196,6 @@ static int vlclua_sd_add_item( lua_State *L )
                 lua_setmetatable( L, -2 );
                 vlc_gc_decref( p_input );
             }
-            free( psz_path );
             while( i_options > 0 )
                 free( ppsz_options[--i_options] );
             free( ppsz_options );
@@ -235,14 +235,15 @@ static int vlclua_node_add_subitem( lua_State *L )
             {
                 char **ppsz_options = NULL;
                 int i_options = 0;
-                char *psz_path = strdup( lua_tostring( L, -1 ) );
-                lua_pop( L, 1 );
+                const char *psz_path = lua_tostring( L, -1 );
                 vlclua_read_options( p_sd, L, &i_options, &ppsz_options );
                 input_item_node_t *p_input_node = input_item_node_Create( *pp_node );
                 input_item_t *p_input = input_item_NewExt( p_sd, psz_path,
                                                            psz_path, i_options,
                                                            (const char **)ppsz_options,
                                                            VLC_INPUT_OPTION_TRUSTED, -1 );
+                lua_pop( L, 1 );
+
                 if( p_input )
                 {
                     vlclua_read_meta_data( p_sd, L, p_input );
@@ -267,7 +268,6 @@ static int vlclua_node_add_subitem( lua_State *L )
                     lua_setmetatable( L, -2 );
                     vlc_gc_decref( p_input );
                 }
-                free( psz_path );
                 while( i_options > 0 )
                     free( ppsz_options[--i_options] );
                 free( ppsz_options );
@@ -292,13 +292,14 @@ static int vlclua_node_add_node( lua_State *L )
             lua_getfield( L, -1, "title" );
             if( lua_isstring( L, -1 ) )
             {
-                char *name = strdup( lua_tostring( L, -1 ) );
-                lua_pop( L, 1 );
+                const char *psz_name = lua_tostring( L, -1 );
                 input_item_node_t *p_input_node = input_item_node_Create( *pp_node );
                 input_item_t *p_input = input_item_NewWithType( VLC_OBJECT( p_sd ),
                                                                 "vlc://nop",
-                                                                name, 0, NULL, 0,
+                                                                psz_name, 0, NULL, 0,
                                                                 -1, ITEM_TYPE_NODE );
+                lua_pop( L, 1 );
+
                 if( p_input )
                 {
                     lua_getfield( L, -1, "arturl" );
@@ -323,7 +324,6 @@ static int vlclua_node_add_node( lua_State *L )
                     }
                     lua_setmetatable( L, -2 );
                 }
-                free( name );
             }
             else
                 msg_Err( p_sd, "node:add_node: the \"title\" parameter can't be empty" );



More information about the vlc-commits mailing list