From patchwork Thu Sep 23 15:28:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30488 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp566977iob; Thu, 23 Sep 2021 08:30:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMgRH1YtcFkXMmYYO5LcKgnLXyk7Zt8XT12/l4DQgJ4fcyr236AwQqctBkj1nALZaB7/Lk X-Received: by 2002:a17:906:1ed7:: with SMTP id m23mr5518521ejj.558.1632411059793; Thu, 23 Sep 2021 08:30:59 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h13si6349944eds.181.2021.09.23.08.30.59; Thu, 23 Sep 2021 08:30:59 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=pxn4BQD9; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F153F68AD15; Thu, 23 Sep 2021 18:29:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-oln040092065047.outbound.protection.outlook.com [40.92.65.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E55AE68AA1F for ; Thu, 23 Sep 2021 18:29:33 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HeyAS2d4hddAuAeBedkYmR9vxAMGqjAhTNy9BC2MEl3TCER893uKU8Y1dcgsGRDvSlrXScD9CRZP4TxotqutM/Hyzr9/s6fov/wswaTUrCjlQ04umuaINB/nvLLEVvoQ4NYo+XN+V5GuRiFK3CY/hwcBq2S5MpIhxgeq+tCSowpzAABbellDi2RZXNlmgemI5lRD+ftBu39J48kd4oaPM42jtZ9rjCUOaMDKSS4vkLQ31M/6VoKOEx697DjLoseTnJRRpJ7s0Dkx9gdOQcJb5MQ1MGvNGQ/Lf0nbphkWNutCP47rc1IS20JptbAc37OMOPMilxGWLCIHhAyXrC0m5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=tUpyz8OZIS0QKYa45UZe78MVf1oVMj2rLmjlVhnBvYM=; b=bCan4SoV7ik6r6cBQFCMv/InBOTMd/zL/cmpixlLAfZiDnz4ozM7/hMVLNS/eZVB+AvK/W6uY9rPof889uli7O7YcgV+EnqxyITyKBAglcAH4ml+OBvDY2b9gYklLiLbpR18fu/YXzcHMUqpKtuhELlxlu/hMAIqirxO1jn4JgiLSTj2KbQj9uexJr2TXPTHyoWbef76FDnOgOqApB8PbhoRXKqxtnQjcPmsiD/fVG9ugDjOXISbJdb1C5SkZc6cyz24YBVv1DiD9WsL2YI0MjFeTU7iS5CeA2DaIGOpSiNeDV+9tEPlR4NHWPJlUoI0424nG4drVnmABCfnC+LKcg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tUpyz8OZIS0QKYa45UZe78MVf1oVMj2rLmjlVhnBvYM=; b=pxn4BQD9S3qKbY9TCyPOR66bzA6lTVONJd5332M0Yzv0huVRQfhgHpi6ktljNNX1iNJJf1QTNN27lQ2Jk54J9iupG9rGOlYZ0rgW6X/WjO4oXJBdU6HwpoZhL0LA4HAa7a2fDhEmOccKCvpmSKChLYR+44Ji+hzVytwpLFaJoQaEg7DfMl9l6af6jGqIkVRxsw4M1MLDm2w5uNM34cCAsi+0iDCr94+/XqLxrdxSMJrPndfc0Sp04tc9a0QdL1adf2bnTf+rjU0/brwGqA+5zyMQ5cfNMHmFOZucCDGEuq7igwTLIsFwPLrPXzKT6cw0DFFfcckkp6MuSBnQQQbDqA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AS8PR03MB7061.eurprd03.prod.outlook.com (2603:10a6:20b:295::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.15; Thu, 23 Sep 2021 15:29:30 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::787b:2156:ca99:fe00]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::787b:2156:ca99:fe00%3]) with mapi id 15.20.4523.021; Thu, 23 Sep 2021 15:29:30 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 23 Sep 2021 17:28:45 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [+SHTkbE62wtJVA7o6A69MlB2MDIgD2bK] X-ClientProxiedBy: AM0PR06CA0106.eurprd06.prod.outlook.com (2603:10a6:208:fa::47) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210923152902.42865-9-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR06CA0106.eurprd06.prod.outlook.com (2603:10a6:208:fa::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.13 via Frontend Transport; Thu, 23 Sep 2021 15:29:30 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d18298fa-928c-4532-8fe0-08d97ea6efec X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiSygBPrM25OmITrtIHMJgdSvZ7y0GoYR9Y4hcJWL0nJxuONI1K8DmgCWYWHXT4xm6w2dN9qWoumjodPGEM4XsNEgD5FPohVX8tsi4XgHUeUimY3ugCv9ZbnjMvb6+aqR3xw7oll7tszNULOyNyrLS31t8RQaCmPcBQGZplItO8g4izdILnh7yGHrP01VjBL77CK/tfdVguTMYK7FqF3msoW0CoIzrkgyB7/sOgPHYjsRAdYXXoMcS0OAw8Mwf53acXaBMm9THtO9U/nWHXY/Ega8+lHRYqUkWVr80ElAjfruhaLw5mEwh+KA7BlPQO+cNpmUu2rXqzExD+b8BE9HaEiiGP5Se3pXdv7GX+zg+QRYYXCgVfv1/CWDYxmIdYN+58pYIO140/n+KiXH80mnWU7ht+pd10mDO/HHY/fBF17OVKa8asAXh/vB76YieaOXIGpBd9I9OH6GArVgsEZ/tXUTkDMPhOe/w2YiCZezim8Es93MpUKW4UzrslLe76qlMw5xezwnbcp1x0xZNU04yB+GbzQRVMMfHavddDQVv7Tn1wh4VULWYWhm+ATwcRYTast2uRX49QyA0oNMzt41lrgALadEqNmkG/jkDIbNx72zNUDUUte3OUnBqlxv3E8iPjfvx6seGtpgh5sWEBqOT9ahBKZz8R0IfuQPODAK45Kaz5KpZJqCOMiz6iNFgrSEPHerwI69uRvrAaYBzescSlWjJly2Q8Mdp181XXUSOkWe+lZ0R95Z3uRpwJF+VTGSVg= X-MS-TrafficTypeDiagnostic: AS8PR03MB7061: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: R/Fz2/nnsGhfbsrsEv7w1ktQsb4FUAMyn8CZ6WfFpFGnLIl+YsrJOd+lopAW5nytX28DhJSRhy3B1yOv/w7IMBji2dymg9qK063Dsi4YvmsauVdZm851yG08fFyDu0AQ1e6nKaEZ22TnzgpeGTKPqK3FOjiSNrawkvhWL98dYrLnJ1Y1pI/sIR7Lavx2xQaCRVXj09JKvJhx1L3D+UNgCp1ixa/4P326FF05VO2oKFT+9zyl65IZVNrPlj4fQ2KyOhfYxdxXGOKAmOMLKvZjARQDWFo6tlZg0UGexWUUrfBsk03W9Qmc7w3hVqsxa3GD+PPA1K91VtSrAoRRvzv0XD0d6TWuJM+iYK1y/9kgV7djuWza1QZNs3t9cskZOA7rHT5BPfvk5tx6FsV8yoiWLVI3RLJf76cPdikhdvv79/HZpo/XzEcK/3y7sloyDK/v X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EvFvpIepIUmHggpHOiS5qBPlBTzDsKQ9Hf1986IFiLK22+bCt561PIiu9fS2A5PbEq9NswLOn+oUEP9zKWrSw0pG3IJHLK9BeboBfma544uu6fSzPoMhwi20aezo9piFDBx29P30SBoFdvAEKLO2Qg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d18298fa-928c-4532-8fe0-08d97ea6efec X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2021 15:29:30.6366 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR03MB7061 Subject: [FFmpeg-devel] [PATCH 10/27] avformat/cafenc: Fix memleak when trailer is never written X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: asQZTbRjJJiM Do this by using the AVStream's priv_data for the buffer holding the packet size data. Signed-off-by: Andreas Rheinhardt --- libavformat/cafenc.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/libavformat/cafenc.c b/libavformat/cafenc.c index b17d2397e9..412b3230e3 100644 --- a/libavformat/cafenc.c +++ b/libavformat/cafenc.c @@ -30,7 +30,6 @@ typedef struct { int64_t data; - uint8_t *pkt_sizes; int size_buffer_size; int size_entries_used; int packets; @@ -209,25 +208,26 @@ static int caf_write_header(AVFormatContext *s) static int caf_write_packet(AVFormatContext *s, AVPacket *pkt) { CAFContext *caf = s->priv_data; + AVStream *const st = s->streams[0]; - if (!s->streams[0]->codecpar->block_align) { - void *pkt_sizes; + if (!st->codecpar->block_align) { + uint8_t *pkt_sizes; int i, alloc_size = caf->size_entries_used + 5U; if (alloc_size < 0) return AVERROR(ERANGE); - pkt_sizes = av_fast_realloc(caf->pkt_sizes, + pkt_sizes = av_fast_realloc(st->priv_data, &caf->size_buffer_size, alloc_size); if (!pkt_sizes) return AVERROR(ENOMEM); - caf->pkt_sizes = pkt_sizes; + st->priv_data = pkt_sizes; for (i = 4; i > 0; i--) { unsigned top = pkt->size >> i * 7; if (top) - caf->pkt_sizes[caf->size_entries_used++] = 128 | top; + pkt_sizes[caf->size_entries_used++] = 128 | top; } - caf->pkt_sizes[caf->size_entries_used++] = pkt->size & 127; + pkt_sizes[caf->size_entries_used++] = pkt->size & 127; caf->packets++; } avio_write(s->pb, pkt->data, pkt->size); @@ -260,10 +260,9 @@ static int caf_write_trailer(AVFormatContext *s) avio_wb64(pb, caf->packets * packet_size); ///< mNumberValidFrames avio_wb32(pb, 0); ///< mPrimingFrames avio_wb32(pb, 0); ///< mRemainderFrames - avio_write(pb, caf->pkt_sizes, caf->size_entries_used); + avio_write(pb, st->priv_data, caf->size_entries_used); } } - av_freep(&caf->pkt_sizes); return 0; }