[FFmpeg-cvslog] avcodec/ass: Fix leaks upon ff_ass_add_rect() error

Andreas Rheinhardt git at videolan.org
Thu Dec 16 04:01:57 EET 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Fri Dec 10 22:42:24 2021 +0100| [2adbb0c2af2cc42a25ab58ef0d4837245f0fbf62] | committer: Andreas Rheinhardt

avcodec/ass: Fix leaks upon ff_ass_add_rect() error

Do this by actually incrementing the counter for the number
of rects at the right time.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2adbb0c2af2cc42a25ab58ef0d4837245f0fbf62
---

 libavcodec/ass.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/ass.c b/libavcodec/ass.c
index 907e2d7b88..725e4d42ba 100644
--- a/libavcodec/ass.c
+++ b/libavcodec/ass.c
@@ -118,22 +118,22 @@ int ff_ass_add_rect(AVSubtitle *sub, const char *dialog,
                     int readorder, int layer, const char *style,
                     const char *speaker)
 {
+    AVSubtitleRect **rects, *rect;
     char *ass_str;
-    AVSubtitleRect **rects;
 
     rects = av_realloc_array(sub->rects, sub->num_rects+1, sizeof(*sub->rects));
     if (!rects)
         return AVERROR(ENOMEM);
     sub->rects = rects;
-    rects[sub->num_rects]       = av_mallocz(sizeof(*rects[0]));
-    if (!rects[sub->num_rects])
+    rect       = av_mallocz(sizeof(*rect));
+    if (!rect)
         return AVERROR(ENOMEM);
-    rects[sub->num_rects]->type = SUBTITLE_ASS;
+    rects[sub->num_rects++] = rect;
+    rect->type = SUBTITLE_ASS;
     ass_str = ff_ass_get_dialog(readorder, layer, style, speaker, dialog);
     if (!ass_str)
         return AVERROR(ENOMEM);
-    rects[sub->num_rects]->ass = ass_str;
-    sub->num_rects++;
+    rect->ass = ass_str;
     return 0;
 }
 



More information about the ffmpeg-cvslog mailing list