[vlc-commits] commit: lua_variables: luaL_optstring returned pointer is valid as long as the value stay on the lua stack (also avoid an strdup). (=?UTF-8?Q?R=C3=A9mi=20Duraffort=20?=)

git at videolan.org git at videolan.org
Sat Dec 4 15:19:47 CET 2010


vlc | branch: master | Rémi Duraffort <ivoire at videolan.org> | Sat Dec  4 15:18:27 2010 +0100| [11a89704974b204d6009b2b4bf143c6f0713aa55] | committer: Rémi Duraffort 

lua_variables: luaL_optstring returned pointer is valid as long as the value stay on the lua stack (also avoid an strdup).

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

 modules/misc/lua/libs/variables.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/modules/misc/lua/libs/variables.c b/modules/misc/lua/libs/variables.c
index 28109c9..ec718b3 100644
--- a/modules/misc/lua/libs/variables.c
+++ b/modules/misc/lua/libs/variables.c
@@ -248,19 +248,19 @@ static int vlclua_libvlc_command( lua_State *L )
     vlc_value_t val_arg;
 
     const char *psz_cmd = luaL_checkstring( L, 1 );
-    val_arg.psz_string = strdup( luaL_optstring( L, 2, "" ) );
-    lua_pop( L, 2 );
+    val_arg.psz_string = (char*)luaL_optstring( L, 2, "" );
 
     int i_type = var_Type( p_this->p_libvlc, psz_cmd );
     if( ! (i_type & VLC_VAR_ISCOMMAND) )
     {
-        free( val_arg.psz_string );
         return luaL_error( L, "libvlc's \"%s\" is not a command",
                            psz_cmd );
     }
 
-    return vlclua_push_ret( L,
-                            var_Set( p_this->p_libvlc, psz_cmd, val_arg ) );
+    int i_ret = var_Set( p_this->p_libvlc, psz_cmd, val_arg );
+    lua_pop( L, 2 );
+
+    return vlclua_push_ret( L, i_ret );
 }
 
 int __vlclua_var_toggle_or_set( lua_State *L, vlc_object_t *p_obj,



More information about the vlc-commits mailing list