summaryrefslogtreecommitdiff
path: root/libavformat/hlsenc.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2019-12-15 11:00:02 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-05-08 15:17:46 +0200
commitfdb6f55209152b2a9b7e97758c8f26d7cb2dc669 (patch)
tree476fe1801b6bf3b1f077a4854173d68494e60cb9 /libavformat/hlsenc.c
parent6825f7c0ba0e2021c47ef13440cefc49e50b0b5f (diff)
avformat/hlsenc: Add deinit function
This fixes memleaks in instances such as: a) When an allocation fails at one of the two places in hls_init() where the error is returned immediately without goto fail first. b) When an error happens when writing the header. c) When an allocation fails at one of the three places in hls_write_trailer() where the error is returned immediately without goto fail first. d) When one decides not to write the trailer at all (e.g. because of errors when writing packets). Furthermore, it removes code duplication and allows to return immediately, without goto fail first. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavformat/hlsenc.c')
-rw-r--r--libavformat/hlsenc.c47
1 files changed, 17 insertions, 30 deletions
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 783bcffe57..abbf283562 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2553,8 +2553,9 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
return ret;
}
-static void hls_free_variant_streams(struct HLSContext *hls)
+static void hls_deinit(AVFormatContext *s)
{
+ HLSContext *hls = s->priv_data;
int i = 0;
AVFormatContext *vtt_oc = NULL;
VariantStream *vs = NULL;
@@ -2586,6 +2587,20 @@ static void hls_free_variant_streams(struct HLSContext *hls)
av_freep(&vs->baseurl);
av_freep(&vs->varname);
}
+
+ for (i = 0; i < hls->nb_ccstreams; i++) {
+ ClosedCaptionsStream *ccs = &hls->cc_streams[i];
+ av_freep(&ccs->ccgroup);
+ av_freep(&ccs->instreamid);
+ av_freep(&ccs->language);
+ }
+
+ ff_format_io_close(s, &hls->m3u8_out);
+ ff_format_io_close(s, &hls->sub_m3u8_out);
+ av_freep(&hls->key_basename);
+ av_freep(&hls->var_streams);
+ av_freep(&hls->cc_streams);
+ av_freep(&hls->master_m3u8_url);
}
static int hls_write_trailer(struct AVFormatContext *s)
@@ -2718,21 +2733,6 @@ failed:
av_free(old_filename);
}
- hls_free_variant_streams(hls);
-
- for (i = 0; i < hls->nb_ccstreams; i++) {
- ClosedCaptionsStream *ccs = &hls->cc_streams[i];
- av_freep(&ccs->ccgroup);
- av_freep(&ccs->instreamid);
- av_freep(&ccs->language);
- }
-
- ff_format_io_close(s, &hls->m3u8_out);
- ff_format_io_close(s, &hls->sub_m3u8_out);
- av_freep(&hls->key_basename);
- av_freep(&hls->var_streams);
- av_freep(&hls->cc_streams);
- av_freep(&hls->master_m3u8_url);
return 0;
}
@@ -3026,20 +3026,6 @@ static int hls_init(AVFormatContext *s)
}
fail:
- if (ret < 0) {
- hls_free_variant_streams(hls);
- for (i = 0; i < hls->nb_ccstreams; i++) {
- ClosedCaptionsStream *ccs = &hls->cc_streams[i];
- av_freep(&ccs->ccgroup);
- av_freep(&ccs->instreamid);
- av_freep(&ccs->language);
- }
- av_freep(&hls->key_basename);
- av_freep(&hls->var_streams);
- av_freep(&hls->cc_streams);
- av_freep(&hls->master_m3u8_url);
- }
-
return ret;
}
@@ -3137,5 +3123,6 @@ AVOutputFormat ff_hls_muxer = {
.write_header = hls_write_header,
.write_packet = hls_write_packet,
.write_trailer = hls_write_trailer,
+ .deinit = hls_deinit,
.priv_class = &hls_class,
};