title: AVFormat lib avformat_free_context
body: <p>i try this code to get duration of a media file:</p>
  
  <pre><code>AVFormatContext* pFormatCtx = NULL;
  avformat_open_input(&amp;pFormatCtx, filename.c_str(), NULL, NULL);
  
  if (pFormatCtx != 0) {
      avformat_find_stream_info(pFormatCtx, NULL);
  
      int64_t media_duration = pFormatCtx-&gt;duration;
      duration = media_duration/AV_TIME_BASE;
  
      avformat_close_input(&amp;pFormatCtx);
      avformat_free_context(pFormatCtx);
  }
  </code></pre>
  
  <p>The problem is if i call avformat_free_context() the app die, if i comment out the line the program works, but i prefer to avoid memory leak.</p>
  
  <p>PS: i call av_register_all() when the program start.</p>