diff mbox series

[FFmpeg-devel,06/10] avformat/hls: fix leak of rendition when dynarray_add fail

Message ID tencent_2069F27CCAACEA3A65C3BDB50068FE01850A@qq.com
State New
Headers show
Series [FFmpeg-devel,01/10] avformat/hls: fix repeated requests for media init section | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Zhao Zhili April 12, 2022, 8:15 a.m. UTC
---
 libavformat/hls.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/hls.c b/libavformat/hls.c
index b5cdf158c6..3ed6007d0d 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -556,7 +556,10 @@  static struct rendition *new_rendition(HLSContext *c, struct rendition_info *inf
     if (!rend)
         return NULL;
 
-    dynarray_add(&c->renditions, &c->n_renditions, rend);
+    if (av_dynarray_add_nofree(&c->renditions, &c->n_renditions, rend) < 0) {
+        av_free(rend);
+        return NULL;
+    }
 
     rend->type = type;
     strcpy(rend->group_id, info->group_id);
@@ -566,9 +569,14 @@  static struct rendition *new_rendition(HLSContext *c, struct rendition_info *inf
     /* add the playlist if this is an external rendition */
     if (info->uri[0]) {
         rend->playlist = new_playlist(c, info->uri, url_base);
-        if (rend->playlist)
-            dynarray_add(&rend->playlist->renditions,
-                         &rend->playlist->n_renditions, rend);
+        if (rend->playlist) {
+            if (av_dynarray_add_nofree(&rend->playlist->renditions,
+                                       &rend->playlist->n_renditions,
+                                       rend) < 0) {
+                /* Don't free rend since it's owned by c->renditions */
+                return NULL;
+            }
+        }
     }
 
     if (info->assoc_language[0]) {