From f3b93c69cebd8ff9bc34ed731d65cc2150914698 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Thu, 5 Dec 2013 09:40:34 -0500 Subject: [PATCH] src/io/source_avcodec.c: do not reuse AVPacket for now, avoiding memory leaks --- src/io/source_avcodec.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/io/source_avcodec.c b/src/io/source_avcodec.c index aa15dea2..b84e700d 100644 --- a/src/io/source_avcodec.c +++ b/src/io/source_avcodec.c @@ -53,7 +53,6 @@ struct _aubio_source_avcodec_t { AVFormatContext *avFormatCtx; AVCodecContext *avCodecCtx; AVFrame *avFrame; - AVPacket avPacket; AVAudioResampleContext *avr; int16_t *output; uint_t read_samples; @@ -184,8 +183,6 @@ aubio_source_avcodec_t * new_aubio_source_avcodec(char_t * path, uint_t samplera if (!avFrame) { AUBIO_ERR("Could not allocate frame for (%s)\n", s->path); } - AVPacket avPacket = s->avPacket; - av_init_packet(&avPacket); /* allocate output for avr */ s->output = (int16_t *)av_malloc(AUBIO_AVCODEC_MIN_BUFFER_SIZE * sizeof(int16_t)); @@ -196,7 +193,6 @@ aubio_source_avcodec_t * new_aubio_source_avcodec(char_t * path, uint_t samplera s->avFormatCtx = avFormatCtx; s->avCodecCtx = avCodecCtx; s->avFrame = avFrame; - s->avPacket = avPacket; s->avr = avr; //av_log_set_level(AV_LOG_QUIET); @@ -214,7 +210,8 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, uint_t * read_sam AVFormatContext *avFormatCtx = s->avFormatCtx; AVCodecContext *avCodecCtx = s->avCodecCtx; AVFrame *avFrame = s->avFrame; - AVPacket avPacket = s->avPacket; + AVPacket avPacket; + av_init_packet (&avPacket); AVAudioResampleContext *avr = s->avr; int16_t *output = s->output; @@ -262,10 +259,10 @@ void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, uint_t * read_sam //for (i = 0; i < out_samples; i ++) { // AUBIO_DBG("%f\n", SHORT_TO_FLOAT(output[i])); //} + av_free_packet(&avPacket); s->avFormatCtx = avFormatCtx; s->avCodecCtx = avCodecCtx; s->avFrame = avFrame; - s->avPacket = avPacket; s->avr = avr; s->output = output; @@ -344,9 +341,6 @@ void del_aubio_source_avcodec(aubio_source_avcodec_t * s){ avcodec_free_frame( &(s->avFrame) ); } s->avFrame = NULL; - if ( &(s->avPacket) != NULL) { - av_free_packet( &(s->avPacket) ); - } if (s->avCodecCtx != NULL) { avcodec_close ( s->avCodecCtx ); } -- 2.11.0