fix leaks

This commit is contained in:
niels
2015-06-18 23:42:41 +02:00
parent b38f9e7c83
commit a27d407b29
6 changed files with 80 additions and 72 deletions

View File

@@ -155,7 +155,9 @@ static int avcodec_decode_video( AVCodecContext *avctx, AVFrame *picture, int *g
veejay_memset( &pkt, 0, sizeof(AVPacket)); veejay_memset( &pkt, 0, sizeof(AVPacket));
pkt.data = data; pkt.data = data;
pkt.size = pktsize; pkt.size = pktsize;
return avcodec_decode_video2( avctx, picture, got_picture, &pkt ); int ret = avcodec_decode_video2( avctx, picture, got_picture, &pkt );
free_av_packet(&pkt);
return ret;
} }
#endif #endif
static void avhelper_close_input_file( AVFormatContext *s ) { static void avhelper_close_input_file( AVFormatContext *s ) {
@@ -267,6 +269,7 @@ further:
if ( avcodec_open( x->codec_ctx, x->codec ) < 0 ) if ( avcodec_open( x->codec_ctx, x->codec ) < 0 )
#endif #endif
{ {
avhelper_close_input_file( x->avformat_ctx );
free(x); free(x);
return NULL; return NULL;
} }
@@ -304,9 +307,10 @@ further:
x->input = yuv_yuv_template( NULL,NULL,NULL, x->codec_ctx->width,x->codec_ctx->height, x->pixfmt ); x->input = yuv_yuv_template( NULL,NULL,NULL, x->codec_ctx->width,x->codec_ctx->height, x->pixfmt );
sws_template sws_tem; sws_template sws_tem;
veejay_memset(&sws_tem, 0,sizeof(sws_template)); veejay_memset(&sws_tem, 0,sizeof(sws_template));
sws_tem.flags = yuv_which_scaler(); sws_tem.flags = yuv_which_scaler();
x->scaler = yuv_init_swscaler( x->input,x->output, &sws_tem, yuv_sws_get_cpu_flags()); x->scaler = yuv_init_swscaler( x->input,x->output, &sws_tem, yuv_sws_get_cpu_flags());
if( x->scaler == NULL ) { if( x->scaler == NULL ) {
veejay_msg(VEEJAY_MSG_ERROR,"FFmpeg: Failed to get scaler context for %dx%d in %d to %dx%d in %d", veejay_msg(VEEJAY_MSG_ERROR,"FFmpeg: Failed to get scaler context for %dx%d in %d to %dx%d in %d",
x->codec_ctx->width,x->codec_ctx->height, x->pixfmt, x->codec_ctx->width,x->codec_ctx->height, x->pixfmt,

View File

@@ -2411,6 +2411,8 @@ int avi_parse_input_file(avi_t *AVI, int getIndex)
if(AVI->anum > AVI_MAX_TRACKS) { if(AVI->anum > AVI_MAX_TRACKS) {
fprintf(stderr, "error - only %d audio tracks supported\n", AVI_MAX_TRACKS); fprintf(stderr, "error - only %d audio tracks supported\n", AVI_MAX_TRACKS);
if( AVI->idx )
free(AVI->idx);
return(-1); return(-1);
} }
@@ -2431,6 +2433,8 @@ int avi_parse_input_file(avi_t *AVI, int getIndex)
} }
else if (strncasecmp (hdrl_data+i,"iavs",4) ==0 && ! auds_strh_seen) { else if (strncasecmp (hdrl_data+i,"iavs",4) ==0 && ! auds_strh_seen) {
fprintf(stderr, "AVILIB: error - DV AVI Type 1 no supported\n"); fprintf(stderr, "AVILIB: error - DV AVI Type 1 no supported\n");
if( AVI->idx )
free(AVI->idx);
return (-1); return (-1);
} }
else else

View File

@@ -577,12 +577,12 @@ int open_video_file(char *filename, editlist * el, int preserve_pathname, int de
el->ctx[n] = avhelper_get_decoder( filename, out_format, width, height ); el->ctx[n] = avhelper_get_decoder( filename, out_format, width, height );
if( el->ctx[n] == NULL ) { if( el->ctx[n] == NULL ) {
pixfmt = test_video_frame( el, n, elfd, el_pixel_format_ ); pixfmt = test_video_frame( el, n, elfd, el_pixel_format_ );
if( pixfmt == -1 ) { if( pixfmt == -1 ) {
veejay_msg(VEEJAY_MSG_ERROR, "Unable to determine video format" ); veejay_msg(VEEJAY_MSG_ERROR, "Unable to determine video format" );
lav_close(elfd);
if(realname) free(realname);
return -1; return -1;
} }
el->pixfmt[n] = pixfmt; el->pixfmt[n] = pixfmt;
@@ -607,7 +607,7 @@ int open_video_file(char *filename, editlist * el, int preserve_pathname, int de
if( !(_fc == CHROMA422 || _fc == CHROMA420 || _fc == CHROMA444 || _fc == CHROMAUNKNOWN || _fc == CHROMA411 || _fc == CHROMA422F || _fc == CHROMA420F)) if( !(_fc == CHROMA422 || _fc == CHROMA420 || _fc == CHROMA444 || _fc == CHROMAUNKNOWN || _fc == CHROMA411 || _fc == CHROMA422F || _fc == CHROMA420F))
{ {
veejay_msg(VEEJAY_MSG_ERROR,"Input file %s is not in a valid format (%d)",filename,_fc); veejay_msg(VEEJAY_MSG_ERROR,"Input file %s is not in a valid format (%d)",filename,_fc);
if(realname) free(realname); if(realname) free(realname);
lav_close( elfd ); lav_close( elfd );
return -1; return -1;

View File

@@ -79,6 +79,8 @@ static int avail_num[SAMPLE_MAX_SAMPLES]; /* an array of freed sample id's */
static void *sample_font_ = NULL; static void *sample_font_ = NULL;
static int sampleadm_state = SAMPLE_PEEK; /* default state */ static int sampleadm_state = SAMPLE_PEEK; /* default state */
static void *sample_cache[SAMPLE_MAX_SAMPLES]; static void *sample_cache[SAMPLE_MAX_SAMPLES];
static editlist *plain_editlist=NULL;
extern void tagParseStreamFX(char *file, xmlDocPtr doc, xmlNodePtr cur, void *font, void *vp); extern void tagParseStreamFX(char *file, xmlDocPtr doc, xmlNodePtr cur, void *font, void *vp);
extern void tag_writeStream( char *file, int n, xmlNodePtr node, void *font, void *vp ); extern void tag_writeStream( char *file, int n, xmlNodePtr node, void *font, void *vp );
extern int vj_tag_size(); extern int vj_tag_size();
@@ -143,6 +145,37 @@ static int int_compare(const void *key1, const void *key2)
#endif #endif
} }
static void sample_close_edl(int s1, editlist *el)
{
/* check if another sample has same EDL */
if( el != NULL ) {
int end = sample_size() + 1;
int same = 0;
int i;
if( el == plain_editlist ) {
same = 1;
}
if( same == 0 ) {
for (i = 1; i < end; i++) {
if (!sample_exists(i) || s1 == i)
continue;
sample_info *b = sample_get(i);
if( b->edit_list == el ) {
same = 1;
break;
}
}
}
if( same == 0 ) {
vj_el_free(el);
}
}
}
int sample_update(sample_info *sample, int s1) { int sample_update(sample_info *sample, int s1) {
/* if(s1 <= 0 || s1 >= SAMPLE_MAX_SAMPLES) return 0; /* if(s1 <= 0 || s1 >= SAMPLE_MAX_SAMPLES) return 0;
if(sample) { if(sample) {
@@ -196,7 +229,7 @@ void *sample_get_dict( int sample_id )
* call before using any other function as sample_skeleton_new * call before using any other function as sample_skeleton_new
* *
****************************************************************************************************/ ****************************************************************************************************/
void sample_init(int len, void *font) void sample_init(int len, void *font, editlist *pedl)
{ {
if (!initialized) { if (!initialized) {
int i; int i;
@@ -212,6 +245,7 @@ void sample_init(int len, void *font)
} }
sample_font_ = font; sample_font_ = font;
plain_editlist = pedl;
} }
void sample_free(void *edl) void sample_free(void *edl)
@@ -220,17 +254,6 @@ void sample_free(void *edl)
return; return;
sample_del_all(edl); sample_del_all(edl);
/*
hscan_t scan;
hash_scan_begin( &scan, (hash_t*) SampleHash );
hnode_t *node;
while( (node = hash_scan_next(&scan)) != NULL )
{
sample_info *info = (sample_info*) node;
sample_del( info->sample_id);
}
hash_free_nodes( SampleHash );
hash_destroy( SampleHash );*/
} }
int sample_set_state(int new_state) int sample_set_state(int new_state)
@@ -893,7 +916,7 @@ int sample_del(int sample_id)
sample_info *si; sample_info *si;
si = sample_get(sample_id); si = sample_get(sample_id);
if (!si) if (!si)
return 0; return 0;
sample_node = hash_lookup(SampleHash, (void *) si->sample_id); sample_node = hash_lookup(SampleHash, (void *) si->sample_id);
if (sample_node) { if (sample_node) {
@@ -926,70 +949,44 @@ int sample_del(int sample_id)
si->viewport = NULL; si->viewport = NULL;
} }
free(si); if(si->edit_list) {
/* check if another sample has same EDL */
sample_close_edl( sample_id, si->edit_list );
}
/* store freed sample_id */ /* store freed sample_id */
avail_num[next_avail_num] = sample_id; avail_num[next_avail_num] = sample_id;
next_avail_num++; next_avail_num++;
hash_delete_free(SampleHash, sample_node); hash_delete_free(SampleHash, sample_node);
sample_cache[ sample_id ] = NULL; sample_cache[ sample_id ] = NULL;
free(si);
return 1; return 1;
} }
return 0; return 0;
} }
static void sample_free_el(void *port) {
int i;
char **keys = vevo_list_properties(port);
if(keys) {
for( i = 0; keys[i] != NULL; i ++ ) {
void *el = NULL;
if(vevo_property_get(port, keys[i], 0, &el ) == VEVO_NO_ERROR ) {
vj_el_free( (editlist*) el );
}
free(keys[i]);
}
free(keys);
}
}
void sample_del_all(void *edl) void sample_del_all(void *edl)
{ {
int end = sample_size(); int end = sample_size() + 1;
int i; int i;
void *port = vpn(VEVO_ANONYMOUS_PORT);
for (i = 1; i < end; i++) { for (i = 1; i < end; i++) {
if (sample_exists(i)) { if (!sample_exists(i))
sample_chain_clear(i); continue;
sample_info *si = sample_get(i);
if(si->edit_list && edl != si->edit_list) {
char key[32];
snprintf(key,sizeof(key), "p%p", si->edit_list );
if( vevo_property_get( port, key, 0, NULL ) == VEVO_ERROR_NOSUCH_PROPERTY ) {
vevo_property_set( port, key, VEVO_ATOM_TYPE_VOIDPTR,1,&(si->edit_list));
}
}
sample_del(i); sample_chain_clear(i);
} sample_del(i);
} }
sample_free_el( port ); veejay_memset( avail_num, 0, sizeof(int) * SAMPLE_MAX_SAMPLES );
vpf(port);
memset( avail_num, 0, sizeof(int) * SAMPLE_MAX_SAMPLES );
next_avail_num = 0; next_avail_num = 0;
this_sample_id = 0; this_sample_id = 0;
hash_free_nodes( SampleHash ); hash_free_nodes( SampleHash );
} }
/**************************************************************************************************** /****************************************************************************************************
@@ -3256,15 +3253,16 @@ xmlNodePtr ParseSample(xmlDocPtr doc, xmlNodePtr cur, sample_info * skel,void *e
****************************************************************************************************/ ****************************************************************************************************/
int sample_read_edl( sample_info *sample ) int sample_read_edl( sample_info *sample )
{ {
char *files[1]; char *files[1] = {0};
int res = 0; int res = 0;
files[0] = sample->edit_list_file; files[0] = sample->edit_list_file;
void *old = sample->edit_list; void *old = sample->edit_list;
//EDL is stored in CWD, samplelist file can be anywhere. Cannot always load samplelists due to //EDL is stored in CWD, samplelist file can be anywhere. Cannot always load samplelists due to
// missing EDL files in CWD. // missing EDL files in CWD.
veejay_msg(VEEJAY_MSG_DEBUG, "Loading '%s' from current working directory" , files[0] ); veejay_msg(VEEJAY_MSG_DEBUG, "Loading '%s' from video sample from current working directory" , files[0] );
sample->edit_list = vj_el_init_with_args( files,1, sample->edit_list = vj_el_init_with_args( files,1,
__sample_project_settings.flags, __sample_project_settings.flags,
@@ -3279,7 +3277,10 @@ int sample_read_edl( sample_info *sample )
{ {
res = 1; res = 1;
sample->soft_edl = 0; sample->soft_edl = 0;
if( old ) vj_el_free( old );
if( old ) {
sample_close_edl( sample->sample_id, old );
}
} }
else else
{ {

View File

@@ -181,7 +181,7 @@ extern int sample_chain_malloc(int sample_id);
extern int sample_chain_free(int sample_id); extern int sample_chain_free(int sample_id);
extern int sample_size(); extern int sample_size();
extern int sample_verify(); extern int sample_verify();
extern void sample_init(int len, void *font); extern void sample_init(int len, void *font, editlist *el);
extern int sample_update(sample_info *sample, int s1); extern int sample_update(sample_info *sample, int s1);
#ifdef HAVE_XML2 #ifdef HAVE_XML2
extern int sample_readFromFile(char *, void *vp, void *ptr, void *font, void *el, int *id, int *mode); extern int sample_readFromFile(char *, void *vp, void *ptr, void *font, void *el, int *id, int *mode);

View File

@@ -1007,8 +1007,8 @@ static int veejay_screen_update(veejay_t * info )
#endif #endif
vj_perform_get_primary_frame_420p(info,c_frame); vj_perform_get_primary_frame_420p(info,c_frame);
if (vj_dfb_update_yuv_overlay(info->dfb, c_frame) != 0) if (vj_dfb_update_yuv_overlay(info->dfb, c_frame) != 0)
{ {
return 0; return 0;
} }
#endif #endif
break; break;
@@ -1018,7 +1018,6 @@ static int veejay_screen_update(veejay_t * info )
if( vj_yuv_put_frame( info->y4m, frame ) == -1 ) { if( vj_yuv_put_frame( info->y4m, frame ) == -1 ) {
veejay_msg(0, "Failed to write a frame!"); veejay_msg(0, "Failed to write a frame!");
veejay_change_state(info,LAVPLAY_STATE_STOP); veejay_change_state(info,LAVPLAY_STATE_STOP);
return 0; return 0;
} }
break; break;
@@ -1772,7 +1771,7 @@ int veejay_init(veejay_t * info, int x, int y,char *arg, int def_tags, int gen_t
} }
sample_init( (info->video_output_width * info->video_output_height), info->font ); sample_init( (info->video_output_width * info->video_output_height), info->font, el );
sample_set_project( info->pixel_format, sample_set_project( info->pixel_format,
info->auto_deinterlace, info->auto_deinterlace,