title: Simple ffmpeg program has memory leaks
body: <p>Environment: Ubuntu 14.04</p>
  
  <p>I compiled the simple source code from ffmpeg tutorial step 1 at <a href="http://dranger.com/ffmpeg/tutorial01.html" rel="nofollow">http://dranger.com/ffmpeg/tutorial01.html</a>. When I run the binary through valgrind, it reports a bunch of memory leaks. Here is one example:</p>
  
  <pre><code>==30270== 389,824 bytes in 1 blocks are possibly lost in loss record 8 of 8
  ==30270==    at 0x4C2D110: memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==30270==    by 0x4C2D227: posix_memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==30270==    by 0x9AEDAD: av_malloc (mem.c:81)
  ==30270==    by 0x9AEEFD: av_mallocz (mem.c:207)
  ==30270==    by 0x74E70F: avcodec_get_context_defaults3 (options.c:102)i
  ==30270==    by 0x74E775: avcodec_alloc_context3 (options.c:130)
  ==30270==    by 0x449737: main (test1.cpp:106)
  </code></pre>
  
  <p>Here is the snippet from test1.cpp at line 106:</p>
  
  <pre><code> pCodecCtx = avcodec_alloc_context3(pCodec);
   if(avcodec_copy_context(pCodecCtx, pCodecCtxOrig) != 0) {
      fprintf(stderr, "Couldn't copy codec context");
      return -1; // Error copying codec context
   }
  </code></pre>
  
  <p>Before the main function returns, it does close the contexts:</p>
  
  <pre><code> avcodec_close(pCodecCtx);
   avcodec_close(pCodecCtxOrig);
   ...
   return 0;
  </code></pre>
  
  <p>Is there something else that need to be done to ensure proper memory release?</p>
  
  <p>For those interested, the source file can be downloaded from the link I mentioned. Regards.</p>