shithub: aubio

Download patch

ref: f3b93c69cebd8ff9bc34ed731d65cc2150914698
parent: d75e2d586d17760dd67d643b9aa0ae9f06175d4f
author: Paul Brossier <[email protected]>
date: Thu Dec 5 04:40:34 EST 2013

src/io/source_avcodec.c: do not reuse AVPacket for now, avoiding memory leaks

--- a/src/io/source_avcodec.c
+++ b/src/io/source_avcodec.c
@@ -53,7 +53,6 @@
   AVFormatContext *avFormatCtx;
   AVCodecContext *avCodecCtx;
   AVFrame *avFrame;
-  AVPacket avPacket;
   AVAudioResampleContext *avr;
   int16_t *output;
   uint_t read_samples;
@@ -184,8 +183,6 @@
   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 @@
   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 @@
   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 @@
   //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 @@
     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 );
   }