diff mbox series

[FFmpeg-devel,v2,03/71] avcodec/ratecontrol: Don't call ff_rate_control_uninit() ourselves

Message ID GV1P250MB073741C7AB5C11E8D931C4EB8FE02@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State New
Headers show
Series [FFmpeg-devel,v2,01/71] avcodec/ratecontrol: Fix double free on error | expand

Commit Message

Andreas Rheinhardt May 11, 2024, 8:50 p.m. UTC
It is currently done inconsistently: Only one error path
(namely the one from init_pass2()) made ff_rate_control_init()
call ff_rate_control_uninit(); in other error paths
cleanup was left to the caller.

Given that the only caller of this function already performs
the necessary cleanup this commit changes this to always
rely on the caller to perform cleanup on error.

Also return the error code from init_pass2().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/ratecontrol.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 78022d80aa..3219e1f60f 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -622,10 +622,9 @@  av_cold int ff_rate_control_init(MpegEncContext *s)
             p = next;
         }
 
-        if (init_pass2(s) < 0) {
-            ff_rate_control_uninit(rcc);
-            return -1;
-        }
+        res = init_pass2(s);
+        if (res < 0)
+            return res;
     }
 
     if (!(s->avctx->flags & AV_CODEC_FLAG_PASS2)) {