<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">I am using the master branch for stream transcoding, reading from memory and sending the transcoded packets to the memory. To accomplish that, I use two AVIOContext variables to feed into input and output AVFormatContext.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I ran into a memory leak after I free all the things I allocated. I traced further, and noticed this in the aviobuf.c.
</p>
<p class="MsoNormal">Note the avio_alloc_context actually allocates the superceding struct FFIOContext, and only returns an element (&s->pub) from FFIOContext.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The question naturally is how am I going to free FFIOContext, not just AVIOConect to plug the memory leak here?</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">AVIOContext *avio_alloc_context(<o:p></o:p></p>
<p class="MsoNormal"> unsigned char *buffer,<o:p></o:p></p>
<p class="MsoNormal"> int buffer_size,<o:p></o:p></p>
<p class="MsoNormal"> int write_flag,<o:p></o:p></p>
<p class="MsoNormal"> void *opaque,<o:p></o:p></p>
<p class="MsoNormal"> int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),<o:p></o:p></p>
<p class="MsoNormal"> int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),<o:p></o:p></p>
<p class="MsoNormal"> int64_t (*seek)(void *opaque, int64_t offset, int whence))<o:p></o:p></p>
<p class="MsoNormal">{<o:p></o:p></p>
<p class="MsoNormal"> FFIOContext *s = av_malloc(sizeof(*s));<o:p></o:p></p>
<p class="MsoNormal"> if (!s)<o:p></o:p></p>
<p class="MsoNormal"> return NULL;<o:p></o:p></p>
<p class="MsoNormal"> ffio_init_context(s, buffer, buffer_size, write_flag, opaque,<o:p></o:p></p>
<p class="MsoNormal"> read_packet, write_packet, seek);<o:p></o:p></p>
<p class="MsoNormal"> return &s->pub;<o:p></o:p></p>
<p class="MsoNormal">}</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,</p>
<p class="MsoNormal">Zed Zhang</p>
</div>
</body>
</html>