avcodec/pngdec: Improve decoding text chunks

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>
This commit is contained in:
Andreas Rheinhardt 2021-03-17 16:49:44 +01:00
parent eda3abd1ec
commit 72cfc80d7b
1 changed files with 4 additions and 3 deletions

View File

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