From patchwork Mon Dec 16 00:04:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 16821 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 ACDEF44A07A for ; Mon, 16 Dec 2019 02:04:58 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9B8D568ACDC; Mon, 16 Dec 2019 02:04:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 660FC68ABC5 for ; Mon, 16 Dec 2019 02:04:47 +0200 (EET) Received: by mail-wm1-f67.google.com with SMTP id q9so4819555wmj.5 for ; Sun, 15 Dec 2019 16:04:47 -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=Ku2c9Hr5dar6Bfi8qX4RFcYTgGUpEg4zSL5Bzw/9Ijg=; b=pWexAoSz+dr+FvE3Y3KgeYigQ+HFahI6owLbvixhbobluk3UUtkLuZrw+SSJwUBm7v IIA0J3RKiLQ8I9EbQVApH+CB6rAEoXMCo6evbYgmRfLNNM/aoINCh3lL6M9RmvI7ntHw KDN0p5D8KZhCly8fF9ddvy6dLkie5SXXYaf2rOWIZOcB4++FbDFqSm5Wqb+Ui1mkQu1b hxDC1HxNhIGEEEp78N138boTCWn0H34mEDx+0IzTn91SkL0z8AWC7N7Cr9/kLPwiKGMk GGsiJKk65igbLpHb5oHQhOw73Jh6+SlWu1nHV1m+bawHjxaqOPOzogf99GYcWb2qTG3t kcTw== 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=Ku2c9Hr5dar6Bfi8qX4RFcYTgGUpEg4zSL5Bzw/9Ijg=; b=Bx1SJNKY13vog73bNs/Fjic6WGr2psV+yBv2LLJI4rHhZleLv2YbeKPZQnWdYwUqt4 duT+d2usWZjqH8LB7TBKV2OTWm6FSMibyDOeOQk/RNwP5+EGIWKfCbl26b8fiu3gK6ug J10glSDLwwsmbadoRnfoNDPNZpAL12H/Mr3JmSXfkOyGG3a4KuWH+CZugx4Xcp3h+hdy G/t/e5H8gTbUS9NmkbaT43xm6l48s/31cOebELJta4NRj9Jx1MxsJmMuCv9J9H1SyU1t sCwLnYBF90AGqIz1yi8xDa0LLeM2+LWfx+aYWbfDjCb1VGkn1Oqznf/Lw3Tnhdm50Jtr Cdlg== X-Gm-Message-State: APjAAAXjOuzowRPkksJo2qI+8IhoJgJZx7p7O0J/u0V4Uy9uGlKpG6Jf Wi2soJiKK3DsTG/emWjpS3KGqrBx X-Google-Smtp-Source: APXvYqynvhJn1oZdvzBacUEiPAW8gLyW0AMTz/Hz0424xGHNL95Wi7ieZbk29PN0h8Z7EwyXiADeiw== X-Received: by 2002:a05:600c:22d3:: with SMTP id 19mr26336638wmg.92.1576454686735; Sun, 15 Dec 2019 16:04:46 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Dec 2019 16:04:46 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 16 Dec 2019 01:04:10 +0100 Message-Id: <20191216000418.24707-9-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 08/16] avformat/hlsenc: Add deinit function 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" 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 --- Strange that this muxer (with its many allocations) didn't have a deinit function before. libavformat/hlsenc.c | 47 ++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 7fcc71264b..8f142fd475 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -2476,8 +2476,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; @@ -2507,6 +2508,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) @@ -2640,21 +2655,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; } @@ -2960,20 +2960,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; } @@ -3069,5 +3055,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, };