avformat/segment: Fix memory leak of cur_entry.filename
authorLvqier <lvqier@gmail.com>
Tue, 8 Dec 2015 11:29:13 +0000 (19:29 +0800)
committerMichael Niedermayer <michael@niedermayer.cc>
Sat, 12 Dec 2015 22:19:22 +0000 (23:19 +0100)
Solution suggested-by: Hendrik Leppkes <h.leppkes@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavformat/segment.c

index 8432d0f..0c1f633 100644 (file)
@@ -183,6 +183,7 @@ static int set_segment_filename(AVFormatContext *s)
     SegmentContext *seg = s->priv_data;
     AVFormatContext *oc = seg->avf;
     size_t size;
+    int ret;
 
     if (seg->segment_idx_wrap)
         seg->segment_idx %= seg->segment_idx_wrap;
@@ -206,9 +207,8 @@ static int set_segment_filename(AVFormatContext *s)
     if (seg->entry_prefix)
         size += strlen(seg->entry_prefix);
 
-    seg->cur_entry.filename = av_mallocz(size);
-    if (!seg->cur_entry.filename)
-        return AVERROR(ENOMEM);
+    if ((ret = av_reallocp(&seg->cur_entry.filename, size)) < 0)
+        return ret;
     snprintf(seg->cur_entry.filename, size, "%s%s",
              seg->entry_prefix ? seg->entry_prefix : "",
              av_basename(oc->filename));