<div dir="auto"><span style="color:rgb(0,0,0)">av_buffer_alloc allocates buffer of given length (it’s data pointer is not null). And after that you </span>replace that pointer to with your own pointer. So, the first allocation get definitely lost.</div><div style="border-color:rgb(255,255,255)!important" dir="auto">You should copy <span style="color:rgb(0,0,0)">pMessageData to </span><span style="color:rgb(0,0,0)">MetaDataBuffer->data (and free </span><span style="color:rgb(0,0,0)">pMessageData manually) or use av_buffer_create function</span><span style="color:rgb(0,0,0)">.</span></div><div style="border-color:rgb(255,255,255)" dir="auto"><span style="color:rgb(0,0,0)"><br></span></div><div style="border-color:rgb(255,255,255)" dir="auto"><span style="color:rgb(0,0,0)">Yurii</span></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Ср, 1 марта 2023 г. в 06:55, Wladislav Artsimovich <ffmpeg@frost.kiwi>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)">Dear FFmpeg and libav users,<br>
<br>
I am using FFmpeg.AutoGen in my C# Program to write out frames encoded <br>
as a h.264 stream and inject per-frame metadata with an unregistered SEI <br>
Message. It works great, but I have a memory leak, which I don't know <br>
how to address. Source file attached.<br>
<br>
Culprit is<br>
```C#<br>
fixed (byte* pMessageData = message)<br>
{<br>
     AVBufferRef* MetaDataBuffer = <br>
ffmpeg.av_buffer_alloc((ulong)message.Length);<br>
     MetaDataBuffer->data = pMessageData;<br>
     AVFrameSideData* sideData = <br>
ffmpeg.av_frame_new_side_data_from_buf(&frame, <br>
AVFrameSideDataType.AV_FRAME_DATA_SEI_UNREGISTERED, MetaDataBuffer);<br>
}<br>
```<br>
I create an AVBuffer, as required by av_frame_new_side_data_from_buf(). <br>
But I cannot free it, resulting in a memory leak. I went through all of <br>
<a href="https://ffmpeg.org/doxygen/trunk/group__lavu__buffer.html" rel="noreferrer" target="_blank">https://ffmpeg.org/doxygen/trunk/group__lavu__buffer.html</a> and tried out <br>
different av_freep() av_free(), av_buffer_unref() functions, changing <br>
when to free etc. When I think I perform the free correctly, nothing <br>
happens. No error, no freeing just nothing. Clearly I misunderstand <br>
something.<br>
To add insult to injury, the Visual Studio profiler cannot look inside <br>
the unmanaged memory of libav and reports, that the heap is fine and not <br>
growing, see attached screenshot.<br>
<br>
How and when can I free this memory created allocated by <br>
av_buffer_alloc() in the attached source file?<br>
<br>
I asked the same question in the FFmpeg.AutoGen Questions Repo. Some <br>
more context there: <br>
<a href="https://github.com/Ruslan-B/FFmpeg.AutoGen.Questions/issues/36" rel="noreferrer" target="_blank">https://github.com/Ruslan-B/FFmpeg.AutoGen.Questions/issues/36</a><br>
<br>
Best regards,<br>
<br>
Vlad<br>
_______________________________________________<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>