diff mbox series

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

Message ID 20210317163202.672493-3-andreas.rheinhardt@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/3] avcodec/pngdec: Use internal AVBPrint string when parsing chunks
Related show

Checks

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

Commit Message

Andreas Rheinhardt March 17, 2021, 4:32 p.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@gmail.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 21e79a24a7..813f16692c 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -539,12 +539,13 @@  static int decode_text_chunk(PNGDecContext *s, uint32_t length, int compressed,
         text_len = data_end - data;
     }
 
-    kw_utf8  = iso88591_to_utf8(keyword, keyword_end - keyword);
     txt_utf8 = iso88591_to_utf8(data, 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);
     }