[FFmpeg-devel] [PATCH 1/6] lavu: improve documentation of some AVFrame functions

Michael Niedermayer michael at niedermayer.cc
Tue Mar 8 18:49:41 CET 2016


On Tue, Mar 01, 2016 at 07:21:36PM +0100, wm4 wrote:
> ---
>  libavutil/frame.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index 76a8123..2d6299b 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -591,6 +591,10 @@ void av_frame_free(AVFrame **frame);
>   * If src is not reference counted, new buffers are allocated and the data is
>   * copied.
>   *
> + * @warning: dst MUST have been either unreferenced with av_frame_unref(dst),
> + *           or newly allocated with av_frame_alloc() before calling this
> + *           function, or undefined behavior will occur.
> + *
>   * @return 0 on success, a negative AVERROR on error
>   */
>  int av_frame_ref(AVFrame *dst, const AVFrame *src);
> @@ -611,6 +615,10 @@ void av_frame_unref(AVFrame *frame);
>  
>  /**
>   * Move everything contained in src to dst and reset src.
> + *
> + * @warning: dst is not unreferenced, but directly overwritten without reading
> + *           or deallocating its contents. Call av_frame_unref(dst) manually
> + *           before calling this function to ensure that no memory is leaked.
>   */
>  void av_frame_move_ref(AVFrame *dst, AVFrame *src);
>  
> @@ -626,6 +634,10 @@ void av_frame_move_ref(AVFrame *dst, AVFrame *src);
>   * necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf.
>   * For planar formats, one buffer will be allocated for each plane.
>   *
> + * @warning: if frame already has been allocated, calling this function will
> + *           leak memory. In addition, undefined behavior can occur in certain
> + *           cases.
> + *
>   * @param frame frame in which to store the new buffers.
>   * @param align required buffer size alignment
>   *
> -- 
> 2.7.0

LGTM, it would be better though if these cases would have defined
behavior, be that a error code or clear abort()/assert(),
undefined behavior always sucks


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

Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160308/26b99872/attachment.sig>


More information about the ffmpeg-devel mailing list