diff mbox series

[FFmpeg-devel,4/4] avcodec/pngdec: Improve decoding text chunks

Message ID DB6PR0101MB2214A6D9AA7521408F9553628F6E9@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com
State Accepted
Commit 72cfc80d7b500a7f66b1bb7373f67f549c1774c6
Headers show
Series [FFmpeg-devel,1/4] avcodec/pngdec: Fix APNG_DISPOSE_OP_BACKGROUND | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt Aug. 21, 2022, 1:36 a.m. UTC
By checking immediately whether the first allocation was successfull
one can simplify the cleanup code in case of errors.

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

Patch

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 132ad40dc9..1d6ca7f4c3 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -551,12 +551,13 @@  static int decode_text_chunk(PNGDecContext *s, GetByteContext *gb, int compresse
         text_len = data_end - data;
     }
 
-    kw_utf8  = iso88591_to_utf8(keyword, keyword_end - keyword);
     txt_utf8 = iso88591_to_utf8(text, text_len);
     if (compressed)
         av_bprint_finalize(&bp, NULL);
-    if (!(kw_utf8 && txt_utf8)) {
-        av_free(kw_utf8);
+    if (!txt_utf8)
+        return AVERROR(ENOMEM);
+    kw_utf8  = iso88591_to_utf8(keyword, keyword_end - keyword);
+    if (!kw_utf8) {
         av_free(txt_utf8);
         return AVERROR(ENOMEM);
     }