[FFmpeg-devel] [PATCH 1/2] avio_alloc_context: Allocate a buffer if NULL is passed

Michael Niedermayer michaelni at gmx.at
Thu May 22 19:06:54 CEST 2014


On Thu, May 22, 2014 at 09:17:28AM +0200, wm4 wrote:
> On Wed, 21 May 2014 22:18:52 +0200
> Michael Niedermayer <michaelni at gmx.at> wrote:
> 
> > Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> > ---
> >  libavformat/aviobuf.c |    9 +++++++++
> >  1 file changed, 9 insertions(+)
> > 
> > diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> > index 738459e..e60574d 100644
> > --- a/libavformat/aviobuf.c
> > +++ b/libavformat/aviobuf.c
> > @@ -119,6 +119,15 @@ AVIOContext *avio_alloc_context(
> >      AVIOContext *s = av_mallocz(sizeof(AVIOContext));
> >      if (!s)
> >          return NULL;
> > +    if (!buffer && !buffer_size)
> > +        buffer_size = IO_BUFFER_SIZE;
> > +    if (!buffer) {
> > +        buffer = av_malloc(buffer_size);
> > +        if (!buffer) {
> > +            av_free(s);
> > +            return NULL;
> > +        }
> > +    }
> >      ffio_init_context(s, buffer, buffer_size, write_flag, opaque,
> >                    read_packet, write_packet, seek);
> >      return s;
> 
> Is the buffer actually free'd?

if the user frees it
do you suggest this should be done automatically ?


> I faintly remember that you have to do
> this manually with custom AVIO contexts.

yes

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I know you won't believe me, but the highest form of Human Excellence is
to question oneself and others. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140522/a3de290c/attachment.asc>


More information about the ffmpeg-devel mailing list