<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hey guys, <div><br></div><div>I’m creating a recording application and I have an incoming frame which I’d like to convert to JPEG without writing it to a movie file.</div><div>However, I need to use libav’s V210 decoder before creating the JPEG data.</div><div><br></div><div>I’m getting a memory leak in this code:</div><div><br></div><div><div style="margin: 0px; font-family: Menlo; color: rgb(112, 61, 170);">AVPacket<span style="color: #000000"> pkt;</span></div><div style="margin: 0px; font-family: Menlo; color: rgb(61, 29, 129);">av_init_packet<span style="color: #000000">(&pkt);</span></div><p style="margin: 0px; font-family: Menlo; min-height: 14px;">            <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-family: Menlo; color: rgb(120, 73, 42);"><span style="color: #000000">pkt.</span><span style="color: #703daa">flags</span><span style="color: #000000"> |= </span>AV_PKT_FLAG_KEY<span style="color: #000000">;</span></div><div style="margin: 0px; font-family: Menlo;">pkt.<span style="color: #703daa">stream_index</span>  = <span style="color: #272ad8">0</span>;</div><div style="margin: 0px; font-family: Menlo;">pkt.<span style="color: #703daa">data</span> = imgData;</div><p style="margin: 0px; font-family: Menlo; min-height: 14px;"><span style="color: rgb(0, 132, 0);">pkt.</span><span style="color: rgb(112, 61, 170);">size</span><span style="color: rgb(0, 132, 0);"> = ...</span></p><p style="margin: 0px; font-family: Menlo; min-height: 14px;">    <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-family: Menlo;"><span style="color: #c7289c">int</span> gotPctr = <span style="color: #272ad8">0</span>;</div><p style="margin: 0px; font-family: Menlo; min-height: 14px;">    <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-family: Menlo;"><span style="color: #703daa">AVFrame</span>* frameGrabFrame = <span style="color: #3d1d81">av_frame_alloc</span>();</div><div style="margin: 0px; font-family: Menlo;"><span style="color: #3d1d81">avcodec_decode_video2</span>(<span style="color: #4f8187">_pV210CodecCtxFrameGrab</span>, frameGrabFrame, &gotPctr, &pkt);</div><p style="margin: 0px; font-family: Menlo; min-height: 14px;">    <br class="webkit-block-placeholder"></p><div style="margin: 0px;">I get a memory consumption increase of about 13 MB after the avcodec_decode call.</div><div style="margin: 0px;">However, I can’t manage to free the memory. I already tried without success:</div><div style="margin: 0px; font-family: Menlo;"><br></div><div style="margin: 0px; font-family: Menlo; color: rgb(61, 29, 129);"><span style="color: #000000">    </span>av_free_packet<span style="color: #000000">(&pkt);</span></div><div style="margin: 0px; font-family: Menlo;">    <span style="color: #3d1d81">av_frame_unref</span>(frameGrabFrame);</div><div style="margin: 0px; font-family: Menlo;">    <span style="color: #3d1d81">av_frame_free</span>(&frameGrabFrame);</div><div><br></div><div><br></div><div>I’m not using reference counting by the way.</div><div>I’m sure that’s a dumb one … sorry for that.</div><div><br></div><div>Any advice appreciated!</div><div>Thanks!</div></div></body></html>