[Libav-user] Question on AVIOContext / FFIOContext - master branch

Zhang, Zed Zed_Zhang at comcast.com
Wed Feb 22 22:21:05 EET 2023


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.

I ran into a memory leak after I free all the things I allocated. I traced further, and noticed this in the aviobuf.c.
Note the avio_alloc_context actually allocates the superceding struct FFIOContext, and only returns an element (&s->pub) from FFIOContext.

The question naturally is how am I going to free FFIOContext, not just AVIOConect to plug the memory leak here?

AVIOContext *avio_alloc_context(
                  unsigned char *buffer,
                  int buffer_size,
                  int write_flag,
                  void *opaque,
                  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
                  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
                  int64_t (*seek)(void *opaque, int64_t offset, int whence))
{
    FFIOContext *s = av_malloc(sizeof(*s));
    if (!s)
        return NULL;
    ffio_init_context(s, buffer, buffer_size, write_flag, opaque,
                  read_packet, write_packet, seek);
    return &s->pub;
}

Thanks,
Zed Zhang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20230222/0ec396db/attachment.htm>


More information about the Libav-user mailing list