diff mbox series

[FFmpeg-devel,10/12] avcodec/xsubdec: Cleanup generically upon allocation error

Message ID AM7PR03MB6660A52CD931553B7E252AD28F729@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 077167fab9067c606c374e0fd26930f78465387b
Headers show
Series [FFmpeg-devel,01/12] avcodec/h2645_parse: Remove H2645NAL.rbsp_buffer | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Dec. 11, 2021, 6:40 p.m. UTC
This is possible by incrementing the counter of allocated rects
directly after said allocation succeeded.

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

Patch

diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c
index 979399bae6..b483699d0a 100644
--- a/libavcodec/xsubdec.c
+++ b/libavcodec/xsubdec.c
@@ -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++)