<div dir="ltr"><div dir="ltr"><div>This is how I am opening output <br></div><div><div style="background-color:rgb(33,33,33);color:rgb(238,255,255)"><pre style="font-family:"Menlo",monospace;font-size:9pt"><span style="color:rgb(195,232,141)">AVFormatContext </span><span style="color:rgb(137,221,255)">*</span>fmtCtx <span style="color:rgb(137,221,255)">= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">;<br></span><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(</span><span style="color:rgb(130,170,255)">avformat_alloc_output_context2</span><span style="color:rgb(137,221,255)">(&</span>fmtCtx<span style="color:rgb(137,221,255)">, </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">, </span>output<span style="color:rgb(137,221,255)">.</span>format<span style="color:rgb(137,221,255)">.</span><span style="color:rgb(130,170,255)">c_str</span><span style="color:rgb(137,221,255)">(), </span>output<span style="color:rgb(137,221,255)">.</span>url<span style="color:rgb(137,221,255)">.</span><span style="color:rgb(130,170,255)">c_str</span><span style="color:rgb(137,221,255)">()) < </span><span style="color:rgb(247,140,108)">0</span><span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)">{<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(255,203,107);font-weight:bold">LOG</span><span style="color:rgb(137,221,255)">(</span>INFO<span style="color:rgb(137,221,255)">) << </span><span style="color:rgb(195,232,141)">"Failed to open mux format context"</span><span style="color:rgb(137,221,255)">;<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">release</span><span style="color:rgb(137,221,255)">();<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(199,146,234);font-style:italic">return false</span><span style="color:rgb(137,221,255)">;<br></span><span style="color:rgb(137,221,255)">}</span></pre></div><br><div style="background-color:rgb(33,33,33);color:rgb(238,255,255)"><pre style="font-family:"Menlo",monospace;font-size:9pt"><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(</span>muxFormatCtx<span style="color:rgb(137,221,255)">.</span><span style="color:rgb(130,170,255)">at</span><span style="color:rgb(137,221,255)">(</span><span style="color:rgb(247,140,108)">0</span><span style="color:rgb(137,221,255)">)-></span>oformat<span style="color:rgb(137,221,255)">-></span>flags <span style="color:rgb(137,221,255)">& </span><span style="color:rgb(255,203,107);font-weight:bold">AVFMT_GLOBALHEADER</span><span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)">{<br></span><span style="color:rgb(137,221,255)"> </span>muxFormatCtx<span style="color:rgb(137,221,255)">.</span><span style="color:rgb(130,170,255)">at</span><span style="color:rgb(137,221,255)">(</span><span style="color:rgb(247,140,108)">0</span><span style="color:rgb(137,221,255)">)-></span>flags <span style="color:rgb(137,221,255)">|= </span><span style="color:rgb(255,203,107);font-weight:bold">AV_CODEC_FLAG_GLOBAL_HEADER</span><span style="color:rgb(137,221,255)">;<br></span><span style="color:rgb(137,221,255)">}<br></span><span style="color:rgb(137,221,255)"><br></span><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(!(</span>muxFormatCtx<span style="color:rgb(137,221,255)">.</span><span style="color:rgb(130,170,255)">at</span><span style="color:rgb(137,221,255)">(</span><span style="color:rgb(247,140,108)">0</span><span style="color:rgb(137,221,255)">)-></span>oformat<span style="color:rgb(137,221,255)">-></span>flags <span style="color:rgb(137,221,255)">& </span><span style="color:rgb(255,203,107);font-weight:bold">AVFMT_NOFILE</span><span style="color:rgb(137,221,255)">))<br></span><span style="color:rgb(137,221,255)">{<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(</span><span style="color:rgb(130,170,255)">avio_open</span><span style="color:rgb(137,221,255)">(&</span>muxFormatCtx<span style="color:rgb(137,221,255)">.</span><span style="color:rgb(130,170,255)">at</span><span style="color:rgb(137,221,255)">(</span><span style="color:rgb(247,140,108)">0</span><span style="color:rgb(137,221,255)">)-></span>pb<span style="color:rgb(137,221,255)">,<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(247,140,108)">pipeline</span><span style="color:rgb(137,221,255)">-></span><span style="color:rgb(130,170,255)">getOutputs</span><span style="color:rgb(137,221,255)">().</span>outputs<span style="color:rgb(137,221,255)">[</span><span style="color:rgb(247,140,108)">0</span><span style="color:rgb(137,221,255)">].</span>url<span style="color:rgb(137,221,255)">.</span><span style="color:rgb(130,170,255)">c_str</span><span style="color:rgb(137,221,255)">(),<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(255,203,107);font-weight:bold">AVIO_FLAG_WRITE</span><span style="color:rgb(137,221,255)">) < </span><span style="color:rgb(247,140,108)">0</span><span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)"> {<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(255,203,107);font-weight:bold">LOG</span><span style="color:rgb(137,221,255)">(</span>INFO<span style="color:rgb(137,221,255)">) << </span><span style="color:rgb(255,203,107)">util</span><span style="color:rgb(137,221,255)">::</span><span style="color:rgb(255,203,107)">string</span><span style="color:rgb(137,221,255)">::</span><span style="color:rgb(255,203,107)">StringFmtUtil</span><span style="color:rgb(137,221,255)">::</span><span style="color:rgb(130,170,255)">format</span><span style="color:rgb(137,221,255)">(</span><span style="color:rgb(195,232,141)">"Could not open output format = %s"</span><span style="color:rgb(137,221,255)">,<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(247,140,108)">pipeline</span><span style="color:rgb(137,221,255)">-></span><span style="color:rgb(130,170,255)">getOutputs</span><span style="color:rgb(137,221,255)">().</span>outputs<span style="color:rgb(137,221,255)">[</span><span style="color:rgb(247,140,108)">0</span><span style="color:rgb(137,221,255)">].</span>url<span style="color:rgb(137,221,255)">.</span><span style="color:rgb(130,170,255)">c_str</span><span style="color:rgb(137,221,255)">());<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">release</span><span style="color:rgb(137,221,255)">();<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(199,146,234);font-style:italic">return false</span><span style="color:rgb(137,221,255)">;<br></span><span style="color:rgb(137,221,255)"> }<br></span><span style="color:rgb(137,221,255)">}<br><br></span></pre><div style="background-color:rgb(33,33,33);color:rgb(238,255,255)"><pre style="font-family:"Menlo",monospace;font-size:9pt"><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(</span><span style="color:rgb(130,170,255)">avformat_write_header</span><span style="color:rgb(137,221,255)">(</span>muxFormatCtx<span style="color:rgb(137,221,255)">.</span><span style="color:rgb(130,170,255)">at</span><span style="color:rgb(137,221,255)">(</span><span style="color:rgb(247,140,108)">0</span><span style="color:rgb(137,221,255)">), </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">) < </span><span style="color:rgb(247,140,108)">0</span><span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)">{<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(255,203,107);font-weight:bold">LOG</span><span style="color:rgb(137,221,255)">(</span>ERROR<span style="color:rgb(137,221,255)">) << </span><span style="color:rgb(195,232,141)">"Error occurred while opening mux format"</span><span style="color:rgb(137,221,255)">;<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">release</span><span style="color:rgb(137,221,255)">();<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(199,146,234);font-style:italic">return false</span><span style="color:rgb(137,221,255)">;<br></span><span style="color:rgb(137,221,255)">}<br><br></span></pre></div><pre style="font-family:"Menlo",monospace;font-size:9pt"><br></pre></div></div></div><div>And this is how i free it <br></div><div><br></div><div><div style="background-color:rgb(33,33,33);color:rgb(238,255,255)"><pre style="font-family:"Menlo",monospace;font-size:9pt"><span style="color:rgb(199,146,234);font-style:italic">for </span><span style="color:rgb(137,221,255)">(</span><span style="color:rgb(199,146,234);font-style:italic">auto </span>formatCtx<span style="color:rgb(137,221,255)">: </span>muxFormatCtx<span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)">{<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(</span>formatCtx <span style="color:rgb(137,221,255)">!= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)"> {<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">av_write_trailer</span><span style="color:rgb(137,221,255)">(</span>formatCtx<span style="color:rgb(137,221,255)">);<br></span><span style="color:rgb(137,221,255)"><br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(!(</span>formatCtx<span style="color:rgb(137,221,255)">-></span>oformat<span style="color:rgb(137,221,255)">-></span>flags <span style="color:rgb(137,221,255)">& </span><span style="color:rgb(255,203,107);font-weight:bold">AVFMT_NOFILE</span><span style="color:rgb(137,221,255)">))<br></span><span style="color:rgb(137,221,255)"> {<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">avio_closep</span><span style="color:rgb(137,221,255)">(&</span>formatCtx<span style="color:rgb(137,221,255)">-></span>pb<span style="color:rgb(137,221,255)">);<br></span><span style="color:rgb(137,221,255)"> }<br></span><span style="color:rgb(137,221,255)"><br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">avformat_free_context</span><span style="color:rgb(137,221,255)">(</span>formatCtx<span style="color:rgb(137,221,255)">);<br></span><span style="color:rgb(137,221,255)"> </span>formatCtx <span style="color:rgb(137,221,255)">= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">;<br></span><span style="color:rgb(137,221,255)"> }<br></span><span style="color:rgb(137,221,255)">}<br></span>muxFormatCtx<span style="color:rgb(137,221,255)">.</span><span style="color:rgb(130,170,255)">clear</span><span style="color:rgb(137,221,255)">();</span></pre></div><br></div><div><br></div><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, May 12, 2025 at 11:20 AM Jaka Bac <<a href="mailto:jakabac@gmail.com">jakabac@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Mon, 12 May 2025 at 11:02, Tomislav Timic <<a href="mailto:tomislavtimic98@gmail.com" target="_blank">tomislavtimic98@gmail.com</a>> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>I was observing my application that is doing transcoding of mpegts over udp and I noticed that constantly after each create of transcoder pipeline and delete of pipeline i get small leaks from avutil. <br><img src="cid:ii_makur3vy0" alt="Screenshot 2025-05-12 at 11.00.07.png" width="558" height="311"><br></div><div>This is how i release input format context <br></div><div><br></div><div><div style="background-color:rgb(33,33,33);color:rgb(238,255,255)"><pre style="font-family:Menlo,monospace;font-size:9pt"><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(</span>formatCtx <span style="color:rgb(137,221,255)">!= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)">{<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">avformat_close_input</span><span style="color:rgb(137,221,255)">(&</span>formatCtx<span style="color:rgb(137,221,255)">);<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">avformat_free_context</span><span style="color:rgb(137,221,255)">(</span>formatCtx<span style="color:rgb(137,221,255)">);<br></span><span style="color:rgb(137,221,255)"> </span>formatCtx <span style="color:rgb(137,221,255)">= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">;<br></span><span style="color:rgb(137,221,255)">}</span></pre></div></div><div>This is how i release decoder <br></div><div><div style="background-color:rgb(33,33,33);color:rgb(238,255,255)"><pre style="font-family:Menlo,monospace;font-size:9pt"><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(</span>frame <span style="color:rgb(137,221,255)">!= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)">{<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">av_frame_free</span><span style="color:rgb(137,221,255)">(&</span>frame<span style="color:rgb(137,221,255)">);<br></span><span style="color:rgb(137,221,255)"> </span>frame <span style="color:rgb(137,221,255)">= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">;<br></span><span style="color:rgb(137,221,255)">}<br></span><span style="color:rgb(137,221,255)"><br></span><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(</span>videoCodecCtx <span style="color:rgb(137,221,255)">!= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)">{<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(</span>videoCodecCtx<span style="color:rgb(137,221,255)">-></span>codec <span style="color:rgb(137,221,255)">!= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr </span><span style="color:rgb(137,221,255)">&&<br></span><span style="color:rgb(137,221,255)"> </span>videoCodecCtx<span style="color:rgb(137,221,255)">-></span>codec<span style="color:rgb(137,221,255)">-></span>capabilities <span style="color:rgb(137,221,255)">& </span><span style="color:rgb(255,203,107);font-weight:bold">AV_CODEC_CAP_ENCODER_FLUSH</span><span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)"> {<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">avcodec_flush_buffers</span><span style="color:rgb(137,221,255)">(</span>videoCodecCtx<span style="color:rgb(137,221,255)">);<br></span><span style="color:rgb(137,221,255)"> }<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">avcodec_free_context</span><span style="color:rgb(137,221,255)">(&</span>videoCodecCtx<span style="color:rgb(137,221,255)">);<br></span><span style="color:rgb(137,221,255)"> </span>videoCodecCtx <span style="color:rgb(137,221,255)">= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">;<br></span><span style="color:rgb(137,221,255)">}<br></span><span style="color:rgb(137,221,255)"><br></span><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(</span>audioCodecCtx <span style="color:rgb(137,221,255)">!= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)">{<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(</span>audioCodecCtx<span style="color:rgb(137,221,255)">-></span>codec <span style="color:rgb(137,221,255)">!= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr </span><span style="color:rgb(137,221,255)">&&<br></span><span style="color:rgb(137,221,255)"> </span>audioCodecCtx<span style="color:rgb(137,221,255)">-></span>codec<span style="color:rgb(137,221,255)">-></span>capabilities <span style="color:rgb(137,221,255)">& </span><span style="color:rgb(255,203,107);font-weight:bold">AV_CODEC_CAP_ENCODER_FLUSH</span><span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)"> {<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">avcodec_flush_buffers</span><span style="color:rgb(137,221,255)">(</span>audioCodecCtx<span style="color:rgb(137,221,255)">);<br></span><span style="color:rgb(137,221,255)"> }<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">avcodec_free_context</span><span style="color:rgb(137,221,255)">(&</span>audioCodecCtx<span style="color:rgb(137,221,255)">);<br></span><span style="color:rgb(137,221,255)"> </span>audioCodecCtx <span style="color:rgb(137,221,255)">= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">;<br></span><span style="color:rgb(137,221,255)">}</span></pre></div>and this is how i release encoder and muxer <br></div><div><br></div><div><div style="background-color:rgb(33,33,33);color:rgb(238,255,255)"><pre style="font-family:Menlo,monospace;font-size:9pt"><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(</span>codecCtx <span style="color:rgb(137,221,255)">!= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)">{<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">avcodec_free_context</span><span style="color:rgb(137,221,255)">(&</span>codecCtx<span style="color:rgb(137,221,255)">);<br></span><span style="color:rgb(137,221,255)"> </span>codecCtx <span style="color:rgb(137,221,255)">= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">;<br></span><span style="color:rgb(137,221,255)">}<br></span><span style="color:rgb(137,221,255)"><br></span><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(</span>encodePkt <span style="color:rgb(137,221,255)">!= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)">{<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">av_packet_free</span><span style="color:rgb(137,221,255)">(&</span>encodePkt<span style="color:rgb(137,221,255)">);<br></span><span style="color:rgb(137,221,255)"> </span>encodePkt <span style="color:rgb(137,221,255)">= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">;<br></span><span style="color:rgb(137,221,255)">}<br><br></span></pre></div><div style="background-color:rgb(33,33,33);color:rgb(238,255,255)"><pre style="font-family:Menlo,monospace;font-size:9pt"><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(</span>packet <span style="color:rgb(137,221,255)">!= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)">{<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">av_packet_free</span><span style="color:rgb(137,221,255)">(&</span>packet<span style="color:rgb(137,221,255)">);<br></span><span style="color:rgb(137,221,255)"> </span>packet <span style="color:rgb(137,221,255)">= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">;<br></span><span style="color:rgb(137,221,255)">}<br></span><span style="color:rgb(137,221,255)"><br></span><span style="color:rgb(199,146,234);font-style:italic">for </span><span style="color:rgb(137,221,255)">(</span><span style="color:rgb(199,146,234);font-style:italic">auto </span>formatCtx<span style="color:rgb(137,221,255)">: </span>muxFormatCtx<span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)">{<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(</span>formatCtx <span style="color:rgb(137,221,255)">!= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">)<br></span><span style="color:rgb(137,221,255)"> {<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">av_write_trailer</span><span style="color:rgb(137,221,255)">(</span>formatCtx<span style="color:rgb(137,221,255)">);<br></span><span style="color:rgb(137,221,255)"><br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(199,146,234);font-style:italic">if </span><span style="color:rgb(137,221,255)">(!(</span>formatCtx<span style="color:rgb(137,221,255)">-></span>oformat<span style="color:rgb(137,221,255)">-></span>flags <span style="color:rgb(137,221,255)">& </span><span style="color:rgb(255,203,107);font-weight:bold">AVFMT_NOFILE</span><span style="color:rgb(137,221,255)">))<br></span><span style="color:rgb(137,221,255)"> {<br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">avio_closep</span><span style="color:rgb(137,221,255)">(&</span>formatCtx<span style="color:rgb(137,221,255)">-></span>pb<span style="color:rgb(137,221,255)">);<br></span><span style="color:rgb(137,221,255)"> }<br></span><span style="color:rgb(137,221,255)"><br></span><span style="color:rgb(137,221,255)"> </span><span style="color:rgb(130,170,255)">avformat_free_context</span><span style="color:rgb(137,221,255)">(</span>formatCtx<span style="color:rgb(137,221,255)">);<br></span><span style="color:rgb(137,221,255)"> </span>formatCtx <span style="color:rgb(137,221,255)">= </span><span style="color:rgb(199,146,234);font-style:italic">nullptr</span><span style="color:rgb(137,221,255)">;<br></span><span style="color:rgb(137,221,255)"> }<br></span><span style="color:rgb(137,221,255)">}</span></pre></div></div></div></blockquote><div><br></div><div>There is no need to do both avformat_close_input() and then avformat_free_context() since avformat_close_input will also free the context.</div><div>avformat_free_context() in your case finds out that it got a null pointer and doesn't do anything.</div><div><br></div><div>As for your leak, how are you opening the output? Maybe you are missing an avio_closep() ?</div></div></div>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".<br>
</blockquote></div></div>