From patchwork Mon Dec 16 00:04:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 16813 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 22CE544A07A for ; Mon, 16 Dec 2019 02:04:51 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 092D668AB17; Mon, 16 Dec 2019 02:04:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 36B3968AA8E for ; Mon, 16 Dec 2019 02:04:43 +0200 (EET) Received: by mail-wm1-f68.google.com with SMTP id q9so4819443wmj.5 for ; Sun, 15 Dec 2019 16:04:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nHbda6+9hk68xAo4mjfY1mVdyVswmF59ZXYqFz+ggoA=; b=cwE5mkteWVjI/ZbVe0Ll3Nhqyg/gHHOoYIt5XEkpOPP4GohRqAFooumUnMbVT28LUV a13fYsTFKCgrhr2cpjDFzutUMRr6v041goD9qDLBLPijubrTi3kQ1ty+PqyWIafv+rEW tQinsmp9+jFEYJVdBQoVfnzawSSkpf5FRoY4H2TKZe+U+GrYdABbjsm71UfMqLgW0ZYc MrqzyxLWpwmHBeCCBp73qcq6EkWWR/OZKOpVMv8tBGUZjN7IQgGCxf1DgXAI0VJqGf3x pXYJ52V3Yqta3kmRGUAnj1SCuq3Mtwq0VpymmPXpQdgwZKU+ZRYAaEEApZey4UemA+fA K5KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nHbda6+9hk68xAo4mjfY1mVdyVswmF59ZXYqFz+ggoA=; b=NFrd+078LCpQdg8oZ/ULk63+zvAbqAukMNLjekgV2ymUUxowlQz6qolr26vrc9o5hU OeGhctIkjLHe/jvxXL4sLN2e1CzPavncBy6XCaVaM1MMEmPMOqht/OsNlkrESvvILdw5 xAyCUg0K2C1/Pa1tk6908FVxtHyS3m5NnIRtSuHnX1GuMJyk/1j4SJNfqBTTGiunI89b DEZdQ8l2k1lBkbS+F2PKz3eVtsrcRTSVwiRh+GzmFeh5rFuuOrloyeig9h88hxPJUHGn a+nJheRmLssiIO9pk+t3j3v8J2TpYGWMeYBIKC8dcFWY/wyic75jASlkTuq3lZogLqze gxZg== X-Gm-Message-State: APjAAAUF/R2Cb5wWqbEIF8mjXldm6O/nsfm5AhEYPhm9FrN6AsOLeG4w Umzo7DSIzaZ47INEBRc5nKP0bnox X-Google-Smtp-Source: APXvYqzVxUgYF9b7WXPVMssOh9a+kHhSvBHcaBSvhfy4tZxno6AEoE+eXgyivN9EWgqNvhTLW31YiA== X-Received: by 2002:a7b:c3d2:: with SMTP id t18mr27750664wmj.90.1576454682518; Sun, 15 Dec 2019 16:04:42 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08e23.dynamic.kabel-deutschland.de. [188.192.142.35]) by smtp.gmail.com with ESMTPSA id s1sm19214442wmc.23.2019.12.15.16.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2019 16:04:42 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 16 Dec 2019 01:04:06 +0100 Message-Id: <20191216000418.24707-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191216000418.24707-1-andreas.rheinhardt@gmail.com> References: <20191216000418.24707-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/16] avformat/hlsenc: Fix leak of options when initializing muxing fails X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" hls_mux_init() currently leaks an AVDictionary if opening a dynamic buffer fails or if avformat_init_output fails. This has been fixed by moving the initialization resp. the freeing of the dictionary around: In the former case to a place after opening the dynamic buffer, in the latter to a place before the check for initialization failure so that it is done unconditionally. Furthermore, the dictionary is now only copied and freed if the options in it are actually used (namely when in SEGMENT_TYPE_FMP4 mode). Finally, a similar situation in hls_start() has been fixed, too. Signed-off-by: Andreas Rheinhardt --- libavformat/hlsenc.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 87bbfb8086..5695af2208 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -835,18 +835,19 @@ static int hls_mux_init(AVFormatContext *s, VariantStream *vs) vs->packets_written = 0; vs->init_range_length = 0; - set_http_options(s, &options, hls); + if ((ret = avio_open_dyn_buf(&oc->pb)) < 0) return ret; if (hls->segment_type == SEGMENT_TYPE_FMP4) { + set_http_options(s, &options, hls); if (byterange_mode) { ret = hlsenc_io_open(s, &vs->out, vs->basename, &options); } else { ret = hlsenc_io_open(s, &vs->out, vs->base_output_dirname, &options); } + av_dict_free(&options); } - av_dict_free(&options); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", vs->fmp4_init_filename); return ret; @@ -861,21 +862,23 @@ static int hls_mux_init(AVFormatContext *s, VariantStream *vs) } } - av_dict_copy(&options, hls->format_options, 0); if (hls->segment_type == SEGMENT_TYPE_FMP4) { + int remaining_options; + + av_dict_copy(&options, hls->format_options, 0); av_dict_set(&options, "fflags", "-autobsf", 0); av_dict_set(&options, "movflags", "+frag_custom+dash+delay_moov", AV_DICT_APPEND); ret = avformat_init_output(oc, &options); + remaining_options = av_dict_count(options); + av_dict_free(&options); if (ret < 0) return ret; - if (av_dict_count(options)) { + if (remaining_options) { av_log(s, AV_LOG_ERROR, "Some of the provided format options in '%s' are not recognized\n", hls->format_options_str); - av_dict_free(&options); return AVERROR(EINVAL); } } avio_flush(oc->pb); - av_dict_free(&options); return 0; } @@ -1650,8 +1653,6 @@ static int hls_start(AVFormatContext *s, VariantStream *vs) } vs->number++; - set_http_options(s, &options, c); - proto = avio_find_protocol_name(oc->url); use_temp_file = proto && !strcmp(proto, "file") && (c->flags & HLS_TEMP_FILE); @@ -1702,6 +1703,7 @@ static int hls_start(AVFormatContext *s, VariantStream *vs) av_opt_set(oc->priv_data, "pat_period", period, 0); } if (c->flags & HLS_SINGLE_FILE) { + set_http_options(s, &options, c); if ((err = hlsenc_io_open(s, &vs->out, oc->url, &options)) < 0) { if (c->ignore_io_errors) err = 0;