diff mbox series

[FFmpeg-devel,4/6] avcodec/h264_slice: use av_buffer_replace() to simplify code

Message ID 20201118130517.585-5-git@gpost.dk
State Accepted
Headers show
Series Use av_buffer_replace() | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Gil Pedersen Nov. 18, 2020, 1:05 p.m. UTC
Signed-off-by: Gil Pedersen <git@gpost.dk>
---
 libavcodec/h264_slice.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Anton Khirnov Nov. 19, 2020, 7:51 a.m. UTC | #1
Quoting Gil Pedersen (2020-11-18 14:05:15)
> Signed-off-by: Gil Pedersen <git@gpost.dk>
> ---
>  libavcodec/h264_slice.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
> index fa7a639053..b937ebebcf 100644
> --- a/libavcodec/h264_slice.c
> +++ b/libavcodec/h264_slice.c
> @@ -1018,11 +1018,11 @@ static int h264_init_ps(H264Context *h, const H264SliceContext *sl, int first_sl
>      int needs_reinit = 0, must_reinit, ret;
>  
>      if (first_slice) {
> -        av_buffer_unref(&h->ps.pps_ref);
> -        h->ps.pps = NULL;
> -        h->ps.pps_ref = av_buffer_ref(h->ps.pps_list[sl->pps_id]);
> -        if (!h->ps.pps_ref)
> -            return AVERROR(ENOMEM);
> +        ret = av_buffer_replace(&h->ps.pps_ref, h->ps.pps_list[sl->pps_id]);
> +        if (ret < 0) {
> +            h->ps.pps = NULL;

You should probably unref pps_ref on failure too, av_buffer_replace()
leaves the original on failure.
diff mbox series

Patch

diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index fa7a639053..b937ebebcf 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1018,11 +1018,11 @@  static int h264_init_ps(H264Context *h, const H264SliceContext *sl, int first_sl
     int needs_reinit = 0, must_reinit, ret;
 
     if (first_slice) {
-        av_buffer_unref(&h->ps.pps_ref);
-        h->ps.pps = NULL;
-        h->ps.pps_ref = av_buffer_ref(h->ps.pps_list[sl->pps_id]);
-        if (!h->ps.pps_ref)
-            return AVERROR(ENOMEM);
+        ret = av_buffer_replace(&h->ps.pps_ref, h->ps.pps_list[sl->pps_id]);
+        if (ret < 0) {
+            h->ps.pps = NULL;
+            return ret;
+        }
         h->ps.pps = (const PPS*)h->ps.pps_ref->data;
     }