Commit 2a4eb1a7 authored by Aakash Singh's avatar Aakash Singh

checkpoint 5

parent 4b9fcc29
......@@ -228,6 +228,9 @@ static void vlcjs_extension_require( js_State *J )
psz_module );
char *psz_fullpath, *psz_package, *sep;
psz_package = strdup( p_ext->psz_name );
if( !psz_package ){
return js_error( J, "memory error" );
}
sep = strrchr( psz_package, '/' );
if( !sep )
{
......@@ -397,6 +400,7 @@ int ScanJSCallback( vlc_object_t *p_this, const char *psz_filename)
if( js_isstring( J, -1 ) )
{
p_ext->psz_title = strdup( js_tostring( J, -1 ) );
}
else
{
......@@ -407,6 +411,10 @@ int ScanJSCallback( vlc_object_t *p_this, const char *psz_filename)
}
js_pop( J, 1 );
if( !p_ext->psz_title ){
return VLC_ENOMEM;
}
/* Get author */
js_getproperty( J, -1, "author" );
p_ext->psz_author = js_tostring( J, -1 );
......@@ -755,8 +763,10 @@ static int GetMenuEntries( extensions_manager_t *p_mgr, extension_t *p_ext,
}
(*pppsz_titles)[ i_idx ] = strdup( js_tostring( J, -1 ) );
(*ppi_ids)[ i_idx ] = i_idx & 0xFFFF;
i_idx++;
js_pop( J, 1 );
if( !(*pppsz_titles)[ i_idx ] ) return VLC_ENOMEM;
i_idx++;
}
}
else
......
......@@ -23,7 +23,7 @@
#include <unistd.h>
#include "./libs/concurrency.h"
#include "libs/concurrency.h"
typedef struct
{
......@@ -52,6 +52,10 @@ static void *Run( void *data )
// code to test out event loop
js_getglobal( J, "print" );
char *fn = strdup(js_ref( J ));
if( !fn ){
vlc_mutex_unlock( &p_sys->execution_lock );
return;
}
char *n;
int i;
vlcjs_enterLoop( J );
......@@ -59,6 +63,7 @@ static void *Run( void *data )
{
js_pushnumber( J, i);
n = strdup(js_ref( J ));
if( !n ) continue;
vlcjs_registerCallback( J, fn, NULL, n);
}
vlc_mutex_unlock( &p_sys->execution_lock );
......
......@@ -26,7 +26,7 @@
#endif
#include <stdlib.h>
#include "./js.h"
#include "js.h"
/*****************************************************************************
* Module descriptor
......
......@@ -184,6 +184,12 @@ static void vlcjs_dialog_create( js_State *J )
p_dlg->p_object = p_this;
p_dlg->psz_title = strdup( psz_title );
if( !p_dlg->psz_title ){
free( p_dlg );
return js_error( J, "no memory" );
}
p_dlg->b_kill = false;
ARRAY_INIT( p_dlg->widgets );
......@@ -194,9 +200,6 @@ static void vlcjs_dialog_create( js_State *J )
vlc_mutex_init( &p_dlg->lock );
vlc_cond_init( &p_dlg->cond );
/** @todo Use the registry instead of __dialog,
so that the user can't tamper with it */
vlcjs_set( J, p_dlg, "__dialog" );
extension_dialog_t **pp_dlg = malloc( sizeof( extension_dialog_t* ) );
......@@ -337,6 +340,9 @@ static void vlcjs_dialog_set_title( js_State *J )
vlc_mutex_unlock( &p_dlg->lock );
if( !p_dlg->psz_title )
return js_error( J, "no memory" );
vlcjs_SetDialogUpdate( J, 1 );
js_pushundefined( J );
......@@ -422,6 +428,10 @@ static void vlcjs_dialog_add_button( js_State *J )
extension_widget_t *p_widget = malloc( sizeof( extension_widget_t ) );
p_widget->type = EXTENSION_WIDGET_BUTTON;
p_widget->psz_text = strdup( js_tostring( J, 1 ) );
if( !p_widget->psz_text ){
free( p_widget );
return js_error( J, "no memory" );
}
vlcjs_create_widget_inner( J, 2, p_widget );
......@@ -447,6 +457,11 @@ static void vlcjs_dialog_add_label( js_State *J )
p_widget->type = EXTENSION_WIDGET_LABEL;
p_widget->psz_text = strdup( js_tostring( J, 1 ) );
if( !p_widget->psz_text ){
free( p_widget );
return js_error( J, "no memory" );
}
vlcjs_create_widget_inner( J, 1, p_widget );
}
......@@ -461,6 +476,11 @@ static void vlcjs_dialog_add_text_inner( js_State *J, int i_type )
p_widget->type = i_type;
if( !js_isnull( J, 1 ) )
p_widget->psz_text = strdup( js_tostring( J, 1 ) );
if( !p_widget->psz_text ){
free( p_widget );
return VLC_ENOMEM;
}
vlcjs_create_widget_inner( J, 1, p_widget );
}
......@@ -480,8 +500,19 @@ static void vlcjs_dialog_add_check_box( js_State *J )
}
extension_widget_t *p_widget = malloc( sizeof( extension_widget_t ) );
if( !p_widget ){
return js_error( J, "no memory" );
}
p_widget->type = EXTENSION_WIDGET_CHECK_BOX;
p_widget->psz_text = strdup( js_tostring( J, 1 ) );
if( !p_widget->psz_text){
free( p_widget );
return js_error( J, "no memory" );
}
p_widget->b_checked = js_toboolean( J, 2 );
vlcjs_create_widget_inner( J, 2, p_widget );
......@@ -532,6 +563,11 @@ static void vlcjs_dialog_add_image( js_State *J )
p_widget->type = EXTENSION_WIDGET_IMAGE;
p_widget->psz_text = strdup( js_tostring( J, 1 ) );
if( !p_widget->psz_text ){
free( p_widget );
return js_error( J, "no memory" );
}
vlcjs_create_widget_inner( J, 1, p_widget );
}
......@@ -666,6 +702,8 @@ static void vlcjs_widget_set_text( js_State *J )
vlc_mutex_unlock( &p_widget->p_dialog->lock );
if( !p_widget->psz_text ) return js_error( J, "no memory" );
vlcjs_SetDialogUpdate( J, 1 );
js_pushundefined( J);
}
......@@ -703,14 +741,11 @@ static void vlcjs_widget_get_text( js_State *J )
extension_dialog_t *p_dlg = p_widget->p_dialog;
vlc_mutex_lock( &p_dlg->lock );
char *psz_text = NULL;
if( p_widget->psz_text )
psz_text = strdup( p_widget->psz_text );
js_pushstring( J, p_widget->psz_text );
vlc_mutex_unlock( &p_dlg->lock );
js_pushstring( J, psz_text );
free( psz_text );
}
static void vlcjs_widget_get_checked( js_State *J )
......@@ -757,7 +792,16 @@ static void vlcjs_widget_add_value( js_State *J )
struct extension_widget_value_t *p_value,
*p_new_value = malloc( sizeof( struct extension_widget_value_t ) );
if( !p_new_value ) return js_error( J, "no memory" );
p_new_value->psz_text = strdup( js_tostring( J, 1 ) );
if( !p_new_value->psz_text ){
free( p_new_value );
return js_error( J, "no memory" );
}
p_new_value->i_id = js_tointeger( J, 2 ); // defaults to 0
vlc_mutex_lock( &p_widget->p_dialog->lock );
......
......@@ -82,6 +82,9 @@ static void vlcjs_memory_stream_new( js_State *J )
vlc_object_t * p_this = vlcjs_get_this( J );
/* FIXME: duplicating the whole buffer is suboptimal. Keeping a reference to the string so that it doesn't get garbage collected would be better */
char * psz_content = strdup( js_tostring( J, 1 ) );
if( !psz_content ){
return js_error( J, "no memory" );
}
stream_t *p_stream = vlc_stream_MemoryNew( p_this, (uint8_t *)psz_content, strlen( psz_content ), false );
vlcjs_stream_new_inner( J, p_stream );
}
......
......@@ -113,6 +113,9 @@ static void vlcjs_resolve_xml_special_chars( js_State *J )
{
const char *psz_cstring = js_tostring( J, 1 );
char *psz_string = strdup( psz_cstring );
if( !psz_string ) return js_error( J, "no memory" );
vlc_xml_decode( psz_string );
js_pushstring( J, psz_string );
free( psz_string );
......
......@@ -187,6 +187,7 @@ static int probe_jsscript(vlc_object_t *obj, const char *filename)
"probe() function was successful", filename );
js_pop( J, 1 );
sys->filename = strdup(filename);
if( !sys->filename ) goto error;
return VLC_SUCCESS;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment