diff mbox series

[FFmpeg-devel,02/10] avformat/hls: fix leak of init section when dynarray_add fail

Message ID tencent_29CEA6254D3308085EB3E2537035CC691505@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
When av_dynarray_add failed, pls->init_sections will be freed,
which leads to leak of all entries of pls->init_sections.
---
 libavformat/hls.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 67c9650e0b..e249810bce 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -463,7 +463,13 @@  static struct segment *get_init_section(struct playlist *pls,
         av_free(sec_ptr);
         return NULL;
     }
-    dynarray_add(&pls->init_sections, &pls->n_init_sections, sec_ptr);
+    if (av_dynarray_add_nofree(&pls->init_sections,
+                               &pls->n_init_sections,
+                               sec_ptr) < 0) {
+        av_free(sec_ptr->url);
+        av_free(sec_ptr);
+        return NULL;
+    }
 
     return sec_ptr;
 }