[FFmpeg-devel] [PATCH] avutil/internal: add FF_ALLOC_ARRAY_OR_GOTO & FF_ALLOCZ_ARRAY_OR_GOTO

Michael Niedermayer michaelni at gmx.at
Sat Apr 19 03:07:03 CEST 2014


On Sat, Apr 19, 2014 at 12:01:00AM +0200, Nicolas George wrote:
> Le nonidi 29 germinal, an CCXXII, Michael Niedermayer a écrit :
> > These are similar to the existing FF_ALLOCZ_OR_GOTO & FF_ALLOC_OR_GOTO
> > 
> > Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> > ---
> >  libavutil/internal.h |   18 ++++++++++++++++++
> >  1 file changed, 18 insertions(+)
> > 
> > diff --git a/libavutil/internal.h b/libavutil/internal.h
> > index 9c5546f..05a017f 100644
> > --- a/libavutil/internal.h
> > +++ b/libavutil/internal.h
> > @@ -133,6 +133,24 @@
> >      }\
> >  }
> >  
> > +#define FF_ALLOC_ARRAY_OR_GOTO(ctx, p, size0, size1, label)\
> > +{\
> > +    p = av_malloc(size0, size1);\
> > +    if (p == NULL) {\
> > +        av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
> > +        goto label;\
> > +    }\
> > +}
> 
> A short doxy would be nice. Or at least, naming the arguments more
> explicitly than size0 and size1. Maybe nelem and elsize, like in SUS.
> 
> A lot of places would require some kind of "ret = AVERROR(ENOMEM);" before
> jumping to the failure label.
> 

> I am not sure about the unconditional log. Especially for OOM: the error
> message is completely redundant with AVERROR(ENOMEM), and someone higher in

i just realized its not redundant, it prints the context in which the
OOM occured, and it could be extended to print the amount of
memory that was attempted to be allocated

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The worst form of inequality is to try to make unequal things equal.
-- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140419/7d2eb0a9/attachment.asc>


More information about the ffmpeg-devel mailing list