<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1256"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi,<div><br></div><div>It would help if we could see how you allocate the AVIOContext, and your main loop.</div><div><br><div><div>Le 27 juin 2015 à 11:33, Mohamed Moanis <<a href="mailto:mohamed_moanis@outlook.com">mohamed_moanis@outlook.com</a>> a écrit :</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="hmmessage" style="font-size: 12pt; font-family: Calibri;"><div dir="ltr"><div dir="ltr"><span style="font-family: Calibri; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">I am implementing a custom IO to read data packets then transcode them.</span><div style="font-family: Calibri; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">The problem I have is memory leakage, which I guess is coming from the custom IO buffer I allocate to read the data.</div><div style="font-family: Calibri; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">I am referring to the avio example. I have exactly the same callback function.</div><div style="font-family: Calibri; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;"><span class="keyword" style="color: rgb(0, 128, 0);">struct </span><a name="_a0" style="color: rgb(61, 87, 140);"></a><a class="code" href="https://www.ffmpeg.org/doxygen/2.3/structbuffer__data.html" style="color: rgb(70, 101, 162); text-decoration: none;">buffer_data</a> {</div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;">    <a name="a1" style="color: rgb(61, 87, 140);"></a><a class="code" href="https://www.ffmpeg.org/doxygen/2.3/audio__convert_8c.html#ae1affc9ca37cfb624959c866a73f83c2" style="color: rgb(70, 101, 162); text-decoration: none;">uint8_t</a> *<a name="a2" style="color: rgb(61, 87, 140);"></a><a class="code" href="https://www.ffmpeg.org/doxygen/2.3/structbuffer__data.html#a017ad9c72fdc7666c29841ddeefc8cd8" style="color: rgb(70, 101, 162); text-decoration: none;">ptr</a>;</div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;">    <span class="keywordtype" style="color: rgb(96, 64, 32);">size_t</span> <a name="a3" style="color: rgb(61, 87, 140);"></a><a class="code" href="https://www.ffmpeg.org/doxygen/2.3/structbuffer__data.html#a9ca6d8ef5edd7f113c04c865f9367f8c" title="size left in the buffer" style="color: rgb(70, 101, 162); text-decoration: none;">size</a>; <span class="comment" style="color: rgb(128, 0, 0);">///< size left in the buffer</span></div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;"><span class="comment" style="color: rgb(128, 0, 0);"></span>};</div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;"></div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;"><span class="keyword" style="color: rgb(0, 128, 0);">static</span> <span class="keywordtype" style="color: rgb(96, 64, 32);">int</span> <a name="a4" style="color: rgb(61, 87, 140);"></a><a class="code" href="https://www.ffmpeg.org/doxygen/2.3/avio__reading_8c.html#a3a86bff38e7cb9093d0a32316b73b29c" style="color: rgb(70, 101, 162); text-decoration: none;">read_packet</a>(<span class="keywordtype" style="color: rgb(96, 64, 32);">void</span> *opaque, <a class="code" href="https://www.ffmpeg.org/doxygen/2.3/audio__convert_8c.html#ae1affc9ca37cfb624959c866a73f83c2" style="color: rgb(70, 101, 162); text-decoration: none;">uint8_t</a> *<a name="a5" style="color: rgb(61, 87, 140);"></a><a class="code" href="https://www.ffmpeg.org/doxygen/2.3/avisynth__c_8h.html#a5bc5fa69bee375df074734a2c4858604" style="color: rgb(70, 101, 162); text-decoration: none;">buf</a>, <span class="keywordtype" style="color: rgb(96, 64, 32);">int</span> buf_size)</div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;">{</div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;">    <span class="keyword" style="color: rgb(0, 128, 0);">struct </span><a class="code" href="https://www.ffmpeg.org/doxygen/2.3/structbuffer__data.html" style="color: rgb(70, 101, 162); text-decoration: none;">buffer_data</a> *bd = (<span class="keyword" style="color: rgb(0, 128, 0);">struct </span><a class="code" href="https://www.ffmpeg.org/doxygen/2.3/structbuffer__data.html" style="color: rgb(70, 101, 162); text-decoration: none;">buffer_data</a> *)opaque;</div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;">    buf_size = <a name="a6" style="color: rgb(61, 87, 140);"></a><a class="code" href="https://www.ffmpeg.org/doxygen/2.3/common_8h.html#a0f84cbd7fd810cd678157c98cbfad4b0" style="color: rgb(70, 101, 162); text-decoration: none;">FFMIN</a>(buf_size, bd-><a class="code" href="https://www.ffmpeg.org/doxygen/2.3/structbuffer__data.html#a9ca6d8ef5edd7f113c04c865f9367f8c" title="size left in the buffer" style="color: rgb(70, 101, 162); text-decoration: none;">size</a>);</div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;"></div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;">    printf(<span class="stringliteral" style="color: rgb(0, 32, 128);">"ptr:%p size:%zu\n"</span>, bd-><a class="code" href="https://www.ffmpeg.org/doxygen/2.3/structbuffer__data.html#a017ad9c72fdc7666c29841ddeefc8cd8" style="color: rgb(70, 101, 162); text-decoration: none;">ptr</a>, bd-><a class="code" href="https://www.ffmpeg.org/doxygen/2.3/structbuffer__data.html#a9ca6d8ef5edd7f113c04c865f9367f8c" title="size left in the buffer" style="color: rgb(70, 101, 162); text-decoration: none;">size</a>);</div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;"></div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;">    <span class="comment" style="color: rgb(128, 0, 0);">/* copy internal buffer data to buf */</span></div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;">    memcpy(buf, bd-><a class="code" href="https://www.ffmpeg.org/doxygen/2.3/structbuffer__data.html#a017ad9c72fdc7666c29841ddeefc8cd8" style="color: rgb(70, 101, 162); text-decoration: none;">ptr</a>, buf_size);</div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;">    bd-><a class="code" href="https://www.ffmpeg.org/doxygen/2.3/structbuffer__data.html#a017ad9c72fdc7666c29841ddeefc8cd8" style="color: rgb(70, 101, 162); text-decoration: none;">ptr</a>  += buf_size;</div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;">    bd-><a class="code" href="https://www.ffmpeg.org/doxygen/2.3/structbuffer__data.html#a9ca6d8ef5edd7f113c04c865f9367f8c" title="size left in the buffer" style="color: rgb(70, 101, 162); text-decoration: none;">size</a> -= buf_size;</div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;"></div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;">    <span class="keywordflow" style="color: rgb(224, 128, 0);">return</span> buf_size;</div><div class="line" style="font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; transition: background-color 0.5s, box-shadow; -webkit-transition: background-color 0.5s, box-shadow;">}</div></div><div style="font-family: Calibri; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br></div><div style="font-family: Calibri; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">When I debug my code, the function is called even after the data was all read. It is called more than a time with the buffer size is zero and later on the ptr itself is null. My question here is why does that happen?</div><div style="font-family: Calibri; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br></div><div style="font-family: Calibri; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">The second question, is how to free the buffer allocated. In my application I require reading a JPEG frame from a camera that is considerable in size. What I do, is  that I free the AVIOContext and it's buffer just after I call avformat_open_input. But I can see the memory usage increasing by an estimate of the frame size each run.</div><div style="font-family: Calibri; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br></div><div style="font-family: Calibri; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Regards.</div><div class="line" style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; -webkit-transition: background-color 0.5s, box-shadow; transition: background-color 0.5s, box-shadow;"><br></div><div class="line" style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; text-indent: -53px; padding-left: 53px; padding-bottom: 0px; margin: 0px; -webkit-transition: background-color 0.5s, box-shadow; transition: background-color 0.5s, box-shadow;"><br></div><br class="Apple-interchange-newline"></div></div></div></blockquote></div><br></div></body></html>