diff options
author | Luca Barbato <lu_zero@gentoo.org> | 2014-12-15 20:38:00 +0100 |
---|---|---|
committer | Vittorio Giovara <vittorio.giovara@gmail.com> | 2014-12-18 23:22:59 +0100 |
commit | 5d839778b9f3edb682b7f71dde4f80f07c75b098 (patch) | |
tree | 9101ef3a1d06eaffcf1f8b270768b58b7cc317e4 /libavutil | |
parent | effa7d2a6a260ca3ce801c180ee6131d67d665fb (diff) | |
download | ffmpeg-5d839778b9f3edb682b7f71dde4f80f07c75b098.tar.gz |
lavu: Refactor side data wiping
And make sure the nb_side_data field is reset as well.
Based on an initial patch from wm4 <nfxjfg@googlemail.com>.
CC: libav-stable@libav.org
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/frame.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/libavutil/frame.c b/libavutil/frame.c index 48df311dd2..32ec47066b 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -54,6 +54,18 @@ static void free_side_data(AVFrameSideData **ptr_sd) av_freep(ptr_sd); } +static void wipe_side_data(AVFrame *frame) +{ + int i; + + for (i = 0; i < frame->nb_side_data; i++) { + free_side_data(&frame->side_data[i]); + } + frame->nb_side_data = 0; + + av_freep(&frame->side_data); +} + AVFrame *av_frame_alloc(void) { AVFrame *frame = av_mallocz(sizeof(*frame)); @@ -284,10 +296,7 @@ void av_frame_unref(AVFrame *frame) { int i; - for (i = 0; i < frame->nb_side_data; i++) { - free_side_data(&frame->side_data[i]); - } - av_freep(&frame->side_data); + wipe_side_data(frame); for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++) av_buffer_unref(&frame->buf[i]); @@ -398,10 +407,7 @@ int av_frame_copy_props(AVFrame *dst, const AVFrame *src) AVFrameSideData *sd_dst = av_frame_new_side_data(dst, sd_src->type, sd_src->size); if (!sd_dst) { - for (i = 0; i < dst->nb_side_data; i++) { - free_side_data(&dst->side_data[i]); - } - av_freep(&dst->side_data); + wipe_side_data(dst); return AVERROR(ENOMEM); } memcpy(sd_dst->data, sd_src->data, sd_src->size); |