From patchwork Mon Sep 7 02:49:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22145 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 7208844B826 for ; Mon, 7 Sep 2020 06:14:01 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 491F96881FE; Mon, 7 Sep 2020 06:14:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AE9DD68819B for ; Mon, 7 Sep 2020 06:13:54 +0300 (EEST) Received: by mail-ed1-f68.google.com with SMTP id i1so11176531edv.2 for ; Sun, 06 Sep 2020 20:13:54 -0700 (PDT) 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=uvBC3dTgrK8b9mrCCOFbIvRLje8PCEQuXnjHCPkzFo8=; b=AxT9hr0A0Py9IKtg5u24iDl3AJqZVpSxeJtwEheK/LeDQtJogt5hbtUS3zJ8isumkR SEa+zkdDj1n+rkvc6Ub3HW+J2XwTnXAEP/gWD7S5nIgB/Er+WG7GVCtn7ORkAuysXEYo PstA6PoWcUYJl3Uz3myoAlXyUEudCCJl72PSjhAum3fJaaaRwXxSyaMPQFjgZ9oLEtDX BcBpdbVBXU8EQ5jODhnS3eQ96u2qqjFHIwmvojQ2mZuf+S92Thh06/IE0EVSOiPPzJlA /WOur90D00Ue7rzReIadmA++mysLXIxR4BWmotzE6jloRjsM5J3ppHllO0xY2DSwpQs2 jPXQ== 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=uvBC3dTgrK8b9mrCCOFbIvRLje8PCEQuXnjHCPkzFo8=; b=SFTUqDuAVGyPE67rnoLS2VlsytCEmaJDFW8w/mkOeumHq/llJ8qU2/RXVBGF1Rr0eh A/85HBtmR4Py67Bi3wKygncW3iM3HK1c5YbBNk/XzCahiDLREK9nCnbfA4mESWgzGQTc BlgXHjz7PqSza2Y30KJeMRRkVvok5Xm0yat/Wt7/FaGUZ6oyRxMdRKmUUmd2uZ1vdvKY DyR/F0aZMp0tTcalJvb0AfQ0MtwvuydfSC2Au65bcBr4sgmnCJU3oEJuSSPAwALRPME3 3HMDF7vvbqIH+J+aLgzaDqCJv39XsVm6Iz0+viWIT6z1A/nVvWSz67Lo1ZAOkj2BJZTS fc+Q== X-Gm-Message-State: AOAM531qdIPUNdEl+V3HTDHvgesjN4q01Wal6Q3cHlshboP7H8Isz5y9 /Wpqg2JRJ1avl52mQJRAgHNL6QqeAWM= X-Google-Smtp-Source: ABdhPJyuUiF7djMHipmdQh6MdqzzatDwfeog6qkuuRkXDAcuUrJNZuFbMxnonFlO3Xxwn3nVZpOClg== X-Received: by 2002:a05:6402:1851:: with SMTP id v17mr2899990edy.46.1599447071515; Sun, 06 Sep 2020 19:51:11 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id a15sm13802048eje.16.2020.09.06.19.51.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2020 19:51:11 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 Sep 2020 04:49:49 +0200 Message-Id: <20200907024952.11697-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200907024952.11697-1-andreas.rheinhardt@gmail.com> References: <20200907024952.11697-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/10] avformat/segment: Free SegmentListEntries in deinit, not write_trailer 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 leaks when the trailer is never written. Signed-off-by: Andreas Rheinhardt --- The allocation of the filename is btw currently unchecked. Actually, using a flexible array member for it would be advantageous (it could then be allocated and freed together with its SegmentListEntry). Flexible array members are C99. Are they allowed or do we support systems that don't support them? libavformat/segment.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libavformat/segment.c b/libavformat/segment.c index 55d7f62ca0..d895e6a678 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -661,6 +661,8 @@ static int select_reference_stream(AVFormatContext *s) static void seg_free(AVFormatContext *s) { SegmentContext *seg = s->priv_data; + SegmentListEntry *cur; + ff_format_io_close(s, &seg->list_pb); if (seg->avf) { if (seg->is_nullctx) @@ -673,6 +675,14 @@ static void seg_free(AVFormatContext *s) av_freep(&seg->times); av_freep(&seg->frames); av_freep(&seg->cur_entry.filename); + + cur = seg->segment_list_entries; + while (cur) { + SegmentListEntry *next = cur->next; + av_freep(&cur->filename); + av_free(cur); + cur = next; + } } static int seg_init(AVFormatContext *s) @@ -981,7 +991,6 @@ static int seg_write_trailer(struct AVFormatContext *s) { SegmentContext *seg = s->priv_data; AVFormatContext *oc = seg->avf; - SegmentListEntry *cur, *next; int ret = 0; if (!oc) @@ -1004,14 +1013,6 @@ fail: av_opt_free(seg); - cur = seg->segment_list_entries; - while (cur) { - next = cur->next; - av_freep(&cur->filename); - av_free(cur); - cur = next; - } - avformat_free_context(oc); seg->avf = NULL; return ret;