diff mbox series

[FFmpeg-devel,2/4] avcodec/pngdec: Use internal AVBPrint string when parsing chunks

Message ID DB6PR0101MB22147FB2D7776C582703ED728F6E9@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com
State Accepted
Commit 3d4a5ef5c198b844cd38be7366957d3ea2354792
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
One saves an allocation in case the string fits into the buffer.

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

Patch

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 8a197d038d..189c3eee89 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -543,10 +543,8 @@  static int decode_text_chunk(PNGDecContext *s, GetByteContext *gb, int compresse
             return AVERROR_INVALIDDATA;
         if ((ret = decode_zbuf(&bp, data, data_end, s->avctx)) < 0)
             return ret;
+        text     = bp.str;
         text_len = bp.len;
-        ret = av_bprint_finalize(&bp, (char **)&text);
-        if (ret < 0)
-            return ret;
     } else {
         text = (uint8_t *)data;
         text_len = data_end - text;
@@ -554,8 +552,8 @@  static int decode_text_chunk(PNGDecContext *s, GetByteContext *gb, int compresse
 
     kw_utf8  = iso88591_to_utf8(keyword, keyword_end - keyword);
     txt_utf8 = iso88591_to_utf8(text, text_len);
-    if (text != data)
-        av_free(text);
+    if (compressed)
+        av_bprint_finalize(&bp, NULL);
     if (!(kw_utf8 && txt_utf8)) {
         av_free(kw_utf8);
         av_free(txt_utf8);