avcodec/pngdec: Use internal AVBPrint string when parsing chunks

One saves an allocation in case the string fits into the buffer.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2021-03-17 15:20:45 +01:00
parent a84087eaf8
commit 3d4a5ef5c1
1 changed files with 3 additions and 5 deletions

View File

@ -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);