avcodec/xsubdec: Cleanup generically upon allocation error

This is possible by incrementing the counter of allocated rects
directly after said allocation succeeded.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2021-12-10 22:44:13 +01:00
parent 2adbb0c2af
commit 077167fab9
1 changed files with 3 additions and 10 deletions

View File

@ -101,10 +101,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
return AVERROR(ENOMEM);
sub->rects[0] = av_mallocz(sizeof(*sub->rects[0]));
if (!sub->rects[0]) {
av_freep(&sub->rects);
if (!sub->rects[0])
return AVERROR(ENOMEM);
}
sub->num_rects = 1;
sub->rects[0]->x = x; sub->rects[0]->y = y;
sub->rects[0]->w = w; sub->rects[0]->h = h;
sub->rects[0]->type = SUBTITLE_BITMAP;
@ -112,14 +111,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr,
sub->rects[0]->data[0] = av_malloc(w * h);
sub->rects[0]->nb_colors = 4;
sub->rects[0]->data[1] = av_mallocz(AVPALETTE_SIZE);
if (!sub->rects[0]->data[0] || !sub->rects[0]->data[1]) {
av_freep(&sub->rects[0]->data[1]);
av_freep(&sub->rects[0]->data[0]);
av_freep(&sub->rects[0]);
av_freep(&sub->rects);
if (!sub->rects[0]->data[0] || !sub->rects[0]->data[1])
return AVERROR(ENOMEM);
}
sub->num_rects = 1;
// read palette
for (i = 0; i < sub->rects[0]->nb_colors; i++)