From d290bb0c540425e937d11ed88e22c68ab97c57eb Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sat, 17 Nov 2018 20:40:53 +0300 Subject: lavf/dashenc: Fix AVDictionary leaks in case of various init errors. --- libavformat/dashenc.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index f552503564..2c872f93a1 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -833,12 +833,12 @@ static int write_manifest(AVFormatContext *s, int final) snprintf(temp_filename, sizeof(temp_filename), use_rename ? "%s.tmp" : "%s", s->url); set_http_options(&opts, c); ret = dashenc_io_open(s, &c->mpd_out, temp_filename, &opts); + av_dict_free(&opts); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename); return ret; } out = c->mpd_out; - av_dict_free(&opts); avio_printf(out, "\n"); avio_printf(out, "m3u8_out, temp_filename, &opts); + av_dict_free(&opts); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename); return ret; } - av_dict_free(&opts); ff_hls_write_playlist_version(c->m3u8_out, 7); @@ -1122,9 +1122,9 @@ static int dash_init(AVFormatContext *s) snprintf(filename, sizeof(filename), "%s%s", c->dirname, os->initfile); set_http_options(&opts, c); ret = s->io_open(s, &os->out, filename, AVIO_FLAG_WRITE, &opts); + av_dict_free(&opts); if (ret < 0) return ret; - av_dict_free(&opts); os->init_start_pos = 0; if (c->format_options_str) { @@ -1145,11 +1145,12 @@ static int dash_init(AVFormatContext *s) av_dict_set_int(&opts, "dash_track_number", i + 1, 0); av_dict_set_int(&opts, "live", 1, 0); } - if ((ret = avformat_init_output(ctx, &opts)) < 0) + ret = avformat_init_output(ctx, &opts); + av_dict_free(&opts); + if (ret < 0) return ret; os->ctx_inited = 1; avio_flush(ctx->pb); - av_dict_free(&opts); av_log(s, AV_LOG_VERBOSE, "Representation %d init segment will be written to: %s\n", i, filename); @@ -1553,9 +1554,9 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) use_rename ? "%s.tmp" : "%s", os->full_path); set_http_options(&opts, c); ret = dashenc_io_open(s, &os->out, os->temp_path, &opts); + av_dict_free(&opts); if (ret < 0) return ret; - av_dict_free(&opts); } //write out the data immediately in streaming mode -- cgit v1.2.3