diff mbox series

[FFmpeg-devel,06/12] avcodec/pgssubdec: Remove redundant freeing code

Message ID AM7PR03MB6660167390C621FC6DD8E31F8F729@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 58228ab9b91a6a6e418fd38942aa84b6fffa7df9
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
The caller of display_end_segment() frees the AVSubtitle on error
in case ENOMEM is returned or err_recognition is set to explode,
so display_end_segment() doesn't have to.

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

Patch

diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c
index 2d5700a51e..d2824f5bbf 100644
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@ -534,10 +534,8 @@  static int display_end_segment(AVCodecContext *avctx, void *data,
         PGSSubObject *object;
 
         sub->rects[i]  = av_mallocz(sizeof(*sub->rects[0]));
-        if (!sub->rects[i]) {
-            avsubtitle_free(sub);
+        if (!sub->rects[i])
             return AVERROR(ENOMEM);
-        }
         sub->num_rects++;
         sub->rects[i]->type = SUBTITLE_BITMAP;
 
@@ -547,10 +545,8 @@  static int display_end_segment(AVCodecContext *avctx, void *data,
             // Missing object.  Should only happen with damaged streams.
             av_log(avctx, AV_LOG_ERROR, "Invalid object id %d\n",
                    ctx->presentation.objects[i].id);
-            if (avctx->err_recognition & AV_EF_EXPLODE) {
-                avsubtitle_free(sub);
+            if (avctx->err_recognition & AV_EF_EXPLODE)
                 return AVERROR_INVALIDDATA;
-            }
             // Leaves rect empty with 0 width and height.
             continue;
         }
@@ -569,16 +565,13 @@  static int display_end_segment(AVCodecContext *avctx, void *data,
             if (object->rle_remaining_len) {
                 av_log(avctx, AV_LOG_ERROR, "RLE data length %u is %u bytes shorter than expected\n",
                        object->rle_data_len, object->rle_remaining_len);
-                if (avctx->err_recognition & AV_EF_EXPLODE) {
-                    avsubtitle_free(sub);
+                if (avctx->err_recognition & AV_EF_EXPLODE)
                     return AVERROR_INVALIDDATA;
-                }
             }
             ret = decode_rle(avctx, sub->rects[i], object->rle, object->rle_data_len);
             if (ret < 0) {
                 if ((avctx->err_recognition & AV_EF_EXPLODE) ||
                     ret == AVERROR(ENOMEM)) {
-                    avsubtitle_free(sub);
                     return ret;
                 }
                 sub->rects[i]->w = 0;
@@ -589,10 +582,8 @@  static int display_end_segment(AVCodecContext *avctx, void *data,
         /* Allocate memory for colors */
         sub->rects[i]->nb_colors    = 256;
         sub->rects[i]->data[1] = av_mallocz(AVPALETTE_SIZE);
-        if (!sub->rects[i]->data[1]) {
-            avsubtitle_free(sub);
+        if (!sub->rects[i]->data[1])
             return AVERROR(ENOMEM);
-        }
 
         if (!ctx->forced_subs_only || ctx->presentation.objects[i].composition_flag & 0x40)
         memcpy(sub->rects[i]->data[1], palette->clut, sub->rects[i]->nb_colors * sizeof(uint32_t));