[Libav-user] How to free an AVBuffer?

Yurii Monakov monakov.y at gmail.com
Thu Mar 2 02:35:10 EET 2023


av_buffer_alloc allocates buffer of given length (it’s data pointer is not
null). And after that you replace that pointer to with your own pointer.
So, the first allocation get definitely lost.
You should copy pMessageData to MetaDataBuffer->data (and free pMessageData
manually) or use av_buffer_create function.

Yurii

Ср, 1 марта 2023 г. в 06:55, Wladislav Artsimovich <ffmpeg at frost.kiwi>:

> Dear FFmpeg and libav users,
>
> I am using FFmpeg.AutoGen in my C# Program to write out frames encoded
> as a h.264 stream and inject per-frame metadata with an unregistered SEI
> Message. It works great, but I have a memory leak, which I don't know
> how to address. Source file attached.
>
> Culprit is
> ```C#
> fixed (byte* pMessageData = message)
> {
>      AVBufferRef* MetaDataBuffer =
> ffmpeg.av_buffer_alloc((ulong)message.Length);
>      MetaDataBuffer->data = pMessageData;
>      AVFrameSideData* sideData =
> ffmpeg.av_frame_new_side_data_from_buf(&frame,
> AVFrameSideDataType.AV_FRAME_DATA_SEI_UNREGISTERED, MetaDataBuffer);
> }
> ```
> I create an AVBuffer, as required by av_frame_new_side_data_from_buf().
> But I cannot free it, resulting in a memory leak. I went through all of
> https://ffmpeg.org/doxygen/trunk/group__lavu__buffer.html and tried out
> different av_freep() av_free(), av_buffer_unref() functions, changing
> when to free etc. When I think I perform the free correctly, nothing
> happens. No error, no freeing just nothing. Clearly I misunderstand
> something.
> To add insult to injury, the Visual Studio profiler cannot look inside
> the unmanaged memory of libav and reports, that the heap is fine and not
> growing, see attached screenshot.
>
> How and when can I free this memory created allocated by
> av_buffer_alloc() in the attached source file?
>
> I asked the same question in the FFmpeg.AutoGen Questions Repo. Some
> more context there:
> https://github.com/Ruslan-B/FFmpeg.AutoGen.Questions/issues/36
>
> Best regards,
>
> Vlad
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20230302/f87e072a/attachment.htm>


More information about the Libav-user mailing list