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

Zhao Zhili quinkblack at foxmail.com
Tue Apr 12 11:15:18 EEST 2022


---
 libavformat/hls.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

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]) {
-- 
2.31.1



More information about the ffmpeg-devel mailing list