mirror of
https://github.com/game-stop/veejay.git
synced 2025-12-16 04:40:11 +01:00
fix some small leaks, sprintf -> snprintf, safe guards
This commit is contained in:
@@ -187,6 +187,7 @@ void *avhelper_get_decoder( const char *filename, int dst_pixfmt, int dst_width,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if LIBAVCODEC_BUILD > 5400
|
#if LIBAVCODEC_BUILD > 5400
|
||||||
|
/* avformat_find_stream_info leaks memory */
|
||||||
err = avformat_find_stream_info( x->avformat_ctx, NULL );
|
err = avformat_find_stream_info( x->avformat_ctx, NULL );
|
||||||
#else
|
#else
|
||||||
err = av_find_stream_info( x->avformat_ctx );
|
err = av_find_stream_info( x->avformat_ctx );
|
||||||
@@ -280,15 +281,16 @@ further:
|
|||||||
while( (av_read_frame(x->avformat_ctx, &(x->pkt)) >= 0 ) ) {
|
while( (av_read_frame(x->avformat_ctx, &(x->pkt)) >= 0 ) ) {
|
||||||
avcodec_decode_video( x->codec_ctx,f,&got_picture, x->pkt.data, x->pkt.size );
|
avcodec_decode_video( x->codec_ctx,f,&got_picture, x->pkt.data, x->pkt.size );
|
||||||
|
|
||||||
|
free_av_packet( &(x->pkt) );
|
||||||
if( got_picture ) {
|
if( got_picture ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
av_free(f);
|
||||||
|
|
||||||
if(!got_picture) {
|
if(!got_picture) {
|
||||||
veejay_msg(VEEJAY_MSG_ERROR, "FFmpeg: Unable to get whole picture from %s", filename );
|
veejay_msg(VEEJAY_MSG_ERROR, "FFmpeg: Unable to get whole picture from %s", filename );
|
||||||
av_free(f);
|
|
||||||
free_av_packet(&(x->pkt));
|
|
||||||
avcodec_close( x->codec_ctx );
|
avcodec_close( x->codec_ctx );
|
||||||
avhelper_close_input_file( x->avformat_ctx );
|
avhelper_close_input_file( x->avformat_ctx );
|
||||||
free(x->output);
|
free(x->output);
|
||||||
@@ -296,9 +298,6 @@ further:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
free_av_packet(&(x->pkt));
|
|
||||||
av_free(f);
|
|
||||||
|
|
||||||
x->pixfmt = x->codec_ctx->pix_fmt;
|
x->pixfmt = x->codec_ctx->pix_fmt;
|
||||||
x->codec_id = x->codec_ctx->codec_id;
|
x->codec_id = x->codec_ctx->codec_id;
|
||||||
x->frame = avcodec_alloc_frame();
|
x->frame = avcodec_alloc_frame();
|
||||||
@@ -314,7 +313,6 @@ further:
|
|||||||
x->codec_ctx->width,x->codec_ctx->height, x->pixfmt,
|
x->codec_ctx->width,x->codec_ctx->height, x->pixfmt,
|
||||||
wid,hei,dst_pixfmt);
|
wid,hei,dst_pixfmt);
|
||||||
av_free(f);
|
av_free(f);
|
||||||
free_av_packet(&(x->pkt));
|
|
||||||
avcodec_close( x->codec_ctx );
|
avcodec_close( x->codec_ctx );
|
||||||
avhelper_close_input_file( x->avformat_ctx );
|
avhelper_close_input_file( x->avformat_ctx );
|
||||||
free(x->output);
|
free(x->output);
|
||||||
|
|||||||
@@ -1120,8 +1120,6 @@ int test_video_frame( editlist *el, int n, lav_file_t *lav,int out_pix_fmt)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
el->decoders[n] = (void*) d;
|
|
||||||
|
|
||||||
res = lav_read_frame( lav, d->tmp_buffer);
|
res = lav_read_frame( lav, d->tmp_buffer);
|
||||||
|
|
||||||
if( res <= 0 )
|
if( res <= 0 )
|
||||||
@@ -1130,7 +1128,8 @@ int test_video_frame( editlist *el, int n, lav_file_t *lav,int out_pix_fmt)
|
|||||||
_el_free_decoder( d );
|
_el_free_decoder( d );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int got_picture = 0;
|
int got_picture = 0;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
switch( decoder_id )
|
switch( decoder_id )
|
||||||
@@ -1169,10 +1168,14 @@ int test_video_frame( editlist *el, int n, lav_file_t *lav,int out_pix_fmt)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
_el_free_decoder( d );
|
||||||
|
return -1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
el->decoders[n] = (void*) d;
|
||||||
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,17 +48,17 @@ static void dump_event_stderr(vevo_port_t *event)
|
|||||||
int vims_id = 0;
|
int vims_id = 0;
|
||||||
char *param = NULL;
|
char *param = NULL;
|
||||||
int i;
|
int i;
|
||||||
char key[10];
|
char key[16];
|
||||||
|
|
||||||
size_t len = vevo_property_element_size(event, "format", 0 );
|
size_t len = vevo_property_element_size(event, "format", 0 );
|
||||||
if(len > 0 )
|
if(len > 0 )
|
||||||
{
|
{
|
||||||
fmt = malloc(sizeof(char) * len);
|
fmt = vj_malloc(sizeof(char) * len);
|
||||||
vevo_property_get( event, "format", 0, &fmt );
|
vevo_property_get( event, "format", 0, &fmt );
|
||||||
}
|
}
|
||||||
name = malloc(sizeof(char) * vevo_property_element_size( event, "description", 0 ));
|
|
||||||
|
name = vj_malloc(sizeof(char) * vevo_property_element_size( event, "description", 0 ));
|
||||||
vevo_property_get( event, "description", 0, &name );
|
vevo_property_get( event, "description", 0, &name );
|
||||||
|
|
||||||
vevo_property_get( event, "arguments", 0, &n_arg );
|
vevo_property_get( event, "arguments", 0, &n_arg );
|
||||||
vevo_property_get( event, "vims_id", 0, &vims_id );
|
vevo_property_get( event, "vims_id", 0, &vims_id );
|
||||||
|
|
||||||
@@ -68,11 +68,11 @@ static void dump_event_stderr(vevo_port_t *event)
|
|||||||
|
|
||||||
for( i = 0; i < n_arg; i ++ )
|
for( i = 0; i < n_arg; i ++ )
|
||||||
{
|
{
|
||||||
sprintf(key, "help_%d", i );
|
snprintf(key,sizeof(key), "help_%d", i );
|
||||||
size_t len2 = vevo_property_element_size( event, key, 0 );
|
size_t len2 = vevo_property_element_size( event, key, 0 );
|
||||||
if(len2 > 0 )
|
if(len2 > 0 )
|
||||||
{
|
{
|
||||||
param = malloc(sizeof(char) * len2 );
|
param = vj_malloc(sizeof(char) * len2 );
|
||||||
vevo_property_get( event, key, 0, ¶m );
|
vevo_property_get( event, key, 0, ¶m );
|
||||||
veejay_msg(VEEJAY_MSG_INFO,"\t\tArgument %d is %s", i, param );
|
veejay_msg(VEEJAY_MSG_INFO,"\t\tArgument %d is %s", i, param );
|
||||||
free(param);
|
free(param);
|
||||||
@@ -81,7 +81,6 @@ static void dump_event_stderr(vevo_port_t *event)
|
|||||||
|
|
||||||
if(fmt) free(fmt);
|
if(fmt) free(fmt);
|
||||||
free(name);
|
free(name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int vj_event_vevo_list_size(void)
|
int vj_event_vevo_list_size(void)
|
||||||
@@ -112,7 +111,7 @@ char *vj_event_vevo_help_vims( int id, int n )
|
|||||||
size_t len = vevo_property_element_size( index_map_[id], key, 0 );
|
size_t len = vevo_property_element_size( index_map_[id], key, 0 );
|
||||||
if(len > 0 )
|
if(len > 0 )
|
||||||
{
|
{
|
||||||
help = (char*) malloc(sizeof(char) * len );
|
help = (char*) vj_malloc(sizeof(char) * len );
|
||||||
vevo_property_get( index_map_[id], key, 0, &help );
|
vevo_property_get( index_map_[id], key, 0, &help );
|
||||||
}
|
}
|
||||||
return help;
|
return help;
|
||||||
@@ -121,9 +120,8 @@ char *vj_event_vevo_help_vims( int id, int n )
|
|||||||
char *vj_event_vevo_list_serialize(void)
|
char *vj_event_vevo_list_serialize(void)
|
||||||
{
|
{
|
||||||
int len = vj_event_vevo_list_size() + 5;
|
int len = vj_event_vevo_list_size() + 5;
|
||||||
char *res = (char*) malloc(sizeof(char) * len + 100 );
|
char *res = (char*) vj_calloc(sizeof(char) * len + 100 );
|
||||||
int i;
|
int i;
|
||||||
memset( res, 0, len );
|
|
||||||
sprintf(res, "%05d", len - 5);
|
sprintf(res, "%05d", len - 5);
|
||||||
for ( i = 0; i < MAX_INDEX ;i ++ )
|
for ( i = 0; i < MAX_INDEX ;i ++ )
|
||||||
{
|
{
|
||||||
@@ -133,8 +131,8 @@ char *vj_event_vevo_list_serialize(void)
|
|||||||
char *format= vj_event_vevo_get_event_format( i );
|
char *format= vj_event_vevo_get_event_format( i );
|
||||||
int name_len = (name == NULL ? 0: strlen( name ));
|
int name_len = (name == NULL ? 0: strlen( name ));
|
||||||
int fmt_len = (format == NULL? 0: strlen( format ));
|
int fmt_len = (format == NULL? 0: strlen( format ));
|
||||||
char tmp[13];
|
char tmp[16];
|
||||||
sprintf( tmp, "%04d%02d%03d%03d",
|
snprintf( tmp,sizeof(tmp),"%04d%02d%03d%03d",
|
||||||
i, vj_event_vevo_get_num_args(i), fmt_len, name_len );
|
i, vj_event_vevo_get_num_args(i), fmt_len, name_len );
|
||||||
veejay_strncat( res, tmp, 12 );
|
veejay_strncat( res, tmp, 12 );
|
||||||
if( format != NULL )
|
if( format != NULL )
|
||||||
@@ -154,15 +152,17 @@ void vj_event_vevo_inline_fire(void *super, int vims_id, const char *format, ...
|
|||||||
va_list ap;
|
va_list ap;
|
||||||
va_start( ap, format );
|
va_start( ap, format );
|
||||||
void *func = NULL;
|
void *func = NULL;
|
||||||
vevo_property_get( index_map_[vims_id], "function", 0, &func );
|
if( vevo_property_get( index_map_[vims_id], "function", 0, &func ) == VEVO_NO_ERROR )
|
||||||
vevo_event f = (vevo_event) func;
|
{
|
||||||
f( super, format, ap );
|
vevo_event f = (vevo_event) func;
|
||||||
|
f( super, format, ap );
|
||||||
|
}
|
||||||
va_end( ap );
|
va_end( ap );
|
||||||
}
|
}
|
||||||
|
|
||||||
void vj_event_vevo_inline_fire_default( void *super, int vims_id, const char *format )
|
void vj_event_vevo_inline_fire_default( void *super, int vims_id, const char *format )
|
||||||
{
|
{
|
||||||
char key[10];
|
char key[16];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
int dval[4] = {0,0,0,0};
|
int dval[4] = {0,0,0,0};
|
||||||
@@ -175,7 +175,7 @@ void vj_event_vevo_inline_fire_default( void *super, int vims_id, const char *f
|
|||||||
// dangerous, dval != atom_type, i != n defaults
|
// dangerous, dval != atom_type, i != n defaults
|
||||||
while( i < n )
|
while( i < n )
|
||||||
{
|
{
|
||||||
sprintf(key, "argument_%d", i );
|
snprintf(key,sizeof(key), "argument_%d", i );
|
||||||
vevo_property_get( index_map_[vims_id], key, 0, &dval[i] );
|
vevo_property_get( index_map_[vims_id], key, 0, &dval[i] );
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -267,7 +267,7 @@ char *vj_event_vevo_get_event_name( int id )
|
|||||||
size_t len = vevo_property_element_size( index_map_[id], "description", 0 );
|
size_t len = vevo_property_element_size( index_map_[id], "description", 0 );
|
||||||
if(len > 0 )
|
if(len > 0 )
|
||||||
{
|
{
|
||||||
descr = (char*) malloc(sizeof(char) * len );
|
descr = (char*) vj_malloc(sizeof(char) * len );
|
||||||
vevo_property_get( index_map_[id], "description", 0, &descr );
|
vevo_property_get( index_map_[id], "description", 0, &descr );
|
||||||
}
|
}
|
||||||
return descr;
|
return descr;
|
||||||
@@ -280,7 +280,7 @@ char *vj_event_vevo_get_event_format( int id )
|
|||||||
size_t len = vevo_property_element_size( index_map_[id], "format", 0 );
|
size_t len = vevo_property_element_size( index_map_[id], "format", 0 );
|
||||||
if(len > 0 )
|
if(len > 0 )
|
||||||
{
|
{
|
||||||
fmt = (char*) malloc(sizeof(char) * len );
|
fmt = (char*) vj_malloc(sizeof(char) * len );
|
||||||
vevo_property_get( index_map_[id], "format", 0, &fmt );
|
vevo_property_get( index_map_[id], "format", 0, &fmt );
|
||||||
}
|
}
|
||||||
return fmt;
|
return fmt;
|
||||||
@@ -299,8 +299,8 @@ int vj_event_vevo_get_default_value(int id, int p)
|
|||||||
int n =0;
|
int n =0;
|
||||||
if(!index_map_[id])
|
if(!index_map_[id])
|
||||||
return 0;
|
return 0;
|
||||||
char key[15];
|
char key[16];
|
||||||
sprintf(key, "argument_%d",p);
|
snprintf(key,sizeof(key), "argument_%d",p);
|
||||||
vevo_property_get(index_map_[id], key, 0, &n );
|
vevo_property_get(index_map_[id], key, 0, &n );
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
@@ -352,15 +352,16 @@ void vj_event_vevo_free(void)
|
|||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
if( index_map_ ) {
|
if( index_map_ ) {
|
||||||
for( i = 0 ; i < MAX_INDEX ; i ++ )
|
for( i = 0 ; i < MAX_INDEX ; i ++ ) {
|
||||||
if( index_map_[i] ) vpf( index_map_[i] );
|
if( index_map_[i] ) vpf( index_map_[i] );
|
||||||
free(index_map_);
|
}
|
||||||
|
free(index_map_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vj_init_vevo_events(void)
|
void vj_init_vevo_events(void)
|
||||||
{
|
{
|
||||||
index_map_ = (vevo_port_t*) vj_calloc(sizeof(vevo_port_t*) * MAX_INDEX );
|
index_map_ = (vevo_port_t**) vj_calloc(sizeof(vevo_port_t*) * MAX_INDEX );
|
||||||
|
|
||||||
index_map_[VIMS_MACRO] = _new_event(
|
index_map_[VIMS_MACRO] = _new_event(
|
||||||
"%d %d",
|
"%d %d",
|
||||||
|
|||||||
Reference in New Issue
Block a user