From patchwork Mon Apr 19 02:06:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26963 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:49c5:0:0:0:0:0 with SMTP id w188csp684704yba; Sun, 18 Apr 2021 19:07:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGIaJHavn1BU9M0QA7aTp7qLt4myxMZyU0Q/2/6/Ckwu9HSFZAzSif0xnpioTfaJet4iBj X-Received: by 2002:a05:6402:785:: with SMTP id d5mr1375174edy.134.1618798020092; Sun, 18 Apr 2021 19:07:00 -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 d17si10621773edj.284.2021.04.18.19.06.59; Sun, 18 Apr 2021 19:07:00 -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=HFZjoGt3; 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 2AF28680B61; Mon, 19 Apr 2021 05:06:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-oln040092069032.outbound.protection.outlook.com [40.92.69.32]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9C105680B72 for ; Mon, 19 Apr 2021 05:06:34 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cC4utgFgwO/e0uLff9zNFRia5RVvnDji7kUcWR3/G+z7YHSBsGJ4eblCwS0IxppEyB53i39RSQcNgGSFmj6pkGrLUfQAPvGedovdrQ63KuPn0Zy1qB+zlf4AV5z27usVQ4J5UdMThKxtX5ziozgDP0VeKp1UomP14QV1LsNHV9sPjYoN6mX68uZ3Q+1WRhlegfFHrqzb15vw6ZsZBKyuTbLEahwEIM9r3T8SW4g2yswLAMkAg7bQCKrgGiihDfAAYjpJ2yX2zzM5Mx3py3njbd8N/X8/S4EkS55juUHGxr/GLoXJEov/Mc9dbTCxJjYMgy32UciUJUaL/SGz6wjPHA== 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:X-MS-Exchange-SenderADCheck; bh=bVcjY6co4h5IkP0hJ40odn+fC1U1G72gYpqJflxRziQ=; b=RBiVIMLYgThzoXPrabuhNIyOJItDKdCAeg3P3891nNrOWjxPk70yke/wwokTjrNbMfgZfrOwAmCAL9cjVgzslsf66SbqzFbf/qng9uOZD9oskiuRaelawN7FW30ZOKmVmoH3JOJPJ5kzhhhom4BrX9bAcMG7QqN0tFQYX4Wmpm0Jbct/NiAc8dryMojHhKALZB+KvFl7yi3pWoi/DT7Peu4lQ1cqM4Z4eGPXd5Nf8+slwmafGdieWNeHnBOQFW5ch5lzHf7/ZMLxkH0YFbNxxF2YvdvAVNzyUalc0iiTIGMtunOZJS+jRBklPY65xFjTZn/BE2EvRGIo57JxrP/moQ== 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=bVcjY6co4h5IkP0hJ40odn+fC1U1G72gYpqJflxRziQ=; b=HFZjoGt3JKdnqhDoZwVDuLruQKpfWxlOisfqtVBnARy6apmMGlBZLPY8ErkiqPjNdOTOKooFpz8e67MRJHfCNIWOiwoONy0Y5bb2DJ9qlrd06tpgblzKfkIVi8SPFnr5K/13Ibp/i/AF4Q/9rx1pHkOCxwPJajOfj+TTC2IqitLWj0TFI8z72VJlJnGS0lLv/kaTaqyys0OuNldh9rb0ap5US7xtk4GbsbFkbyu74sTcLgaMLy784gy1sP/thHm9vqeIcTd/Kskq5LSvjIQlGbzUpIt5e+7FAZM6MmrwGPZR+kv9mX4Y+HlC8PZ+zZ6lS8hd4Vg4pI4bfqPf8Q7Rbw== Received: from HE1EUR02FT005.eop-EUR02.prod.protection.outlook.com (2a01:111:e400:7e1d::48) by HE1EUR02HT223.eop-EUR02.prod.protection.outlook.com (2a01:111:e400:7e1d::184) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16; Mon, 19 Apr 2021 02:06:33 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:7e1d::41) by HE1EUR02FT005.mail.protection.outlook.com (2a01:111:e400:7e1d::99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Mon, 19 Apr 2021 02:06:33 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:4840C14E28DD472D904F7BE97A3E2A9E7972166EEC650DEDA455BFFA5FAABD95; UpperCasedChecksum:70D18CF27E7AEBEF15CE1F54F148B8FF4A25B7A7E674B6B6A86242BCF89344C7; SizeAsReceived:7597; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::45bb:c44f:2b75:23b7]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::45bb:c44f:2b75:23b7%5]) with mapi id 15.20.4042.024; Mon, 19 Apr 2021 02:06:33 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 Apr 2021 04:06:13 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [HL/ESh11LFq/l+nWltgWSzjxhGake7+e] X-ClientProxiedBy: AM4PR0501CA0051.eurprd05.prod.outlook.com (2603:10a6:200:68::19) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210419020614.92961-5-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.137.96) by AM4PR0501CA0051.eurprd05.prod.outlook.com (2603:10a6:200:68::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19 via Frontend Transport; Mon, 19 Apr 2021 02:06:32 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 6354c7eb-34a5-4f59-bed0-08d902d7c130 X-MS-Exchange-SLBlob-MailProps: q+fD6XS3/UL5of3Fna0zoENiR+FBTuR3hoy8konuS+d5XzaBeLhtEyELhrR928bDosVKq3ZRLT4q7VAzpJ2XTfcFHnndsys1YMYm1GkrFc/Re3TdF50uYroE5jHQPqIFtm8Vfvxtncw26ikGX69I8yvV16uY8AxxmeCTt1KjWhjvXukTFdgJg2Z5NTvi9l7sD89V3lSU86JcRJBuiFPXpTSKdlvU72Eu7Kc+96uRD1u432B5bKbHrLvph7r08YbdFdoJAXGWVoNemyz5OpHXVdPoLQ0tKPsGFjQkfIRx34n+/suYM5GxGfr9/iihjvr31BwB3fWEqRY79avJr87GLBXZHEuVSir8kLfFNv+xIzul8Ff2EY8AcJTz2ZxVkJmE+2uotqXlIzkc3QmCfpIzA1wcQqZjXNyRXfmxzdaBteEqjFhzEthBXFXA1ILYpuQPB6e4Rt/1yrHYp7SHI65VOQAj4y6nj0c71PSO0AqIggaMHaxJbdwlIbzMXX/mgtqbPrxkdOc5mmBCUDaN8d6dH/DlmNE6u6Xx+LDoxnUbHbLuJoSUzEFBnNb+bDl4BhGTkd2RBmYeLF5hixwkd6tvDAVdW0O77Q5ZE4x2pNFuCVFDYlsq7pzCJ1+jiPSvmH/Q5j1VMctVKUuyejRY6ZKUd9ogInK7e7UBzVkSlSF9VOL3QJ5oei5rE2UVkMzZRJH0nv/dSz2EBQMXWRjmC7qfrQ== X-MS-TrafficTypeDiagnostic: HE1EUR02HT223: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3BKmjXSerRkrjra2BWykRFAFjze9nSz8SYhK+Py+DnRvTwYvrgfg34sCl7Ndejl55t8s2KDraTHxORCh9zZIypGpWkCer66b3Nk3QQGuY/V+QzkQcEIClL77KP057yziBbvRpSt3XHGu3pPvPyuMpIWRs0zJaU+YsYp2z47OvtbY5n+adpwvUhhquf401NM8SEbhZppx/KIW+CEEj017ezkBoSn/df7T8Mzx9daSNxWxE1SLEFPRCpOSJP7g1ws+68D4Cn3KBWDqfvVAkOQq0c2UunNxeihsphlBXy7LMBf9Edy6m7NFU30FAuWLvVfR6kQI6x2V0A4MLsi7tza1hRSeUf0iv2bd8lr0vxPbAgYRNJCUD6P5QzbaBY9+RrigAh7+jX14MWJE6n0EBec3uQ== X-MS-Exchange-AntiSpam-MessageData: qj+tOFAWDltTmHht0IJzSD9e+hQahKVl6bKopXS62zbpTrqM0RnYTl+m8cYKR5qkqzHkJ7RRvAdetXPJhgIoCGdVv91SNre5axeD+iH6aeU6VSnOsb+ftNg2DIoXW4XHtB3T4ePX1TTjwFcqhjD7lQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6354c7eb-34a5-4f59-bed0-08d902d7c130 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2021 02:06:33.4186 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: HE1EUR02FT005.eop-EUR02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1EUR02HT223 Subject: [FFmpeg-devel] [PATCH 6/7] avcodec/avcodec: Use avcodec_close() on avcodec_open2() failure 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: /9X4JaSIcBsq Content-Length: 3509 Compared to the earlier behaviour the following changes: a) AVCodecInternal.byte_buffer is freed. b) The last_pkt_props FIFO is emptied before freeing it. c) If set AVCodecContext.hwaccel is uninitialized and its private data is freed; hw_frames_ctx and hw_device_ctx are also unreferenced. d) coded_side_data is freed. e) active_thread_type is reset. a), b), d) should be no-ops as the buffer/fifo should be empty and no coded_side_data should exist at any point of avcodec_open2(). e) is obviously not bad. c) is in accordance with the documentation of hw_(frames|device)_ctx which states that libacodec takes over ownership of these references. At least in the case of VC-1 it is possible for the hw acceleration to be set during init and in this case freeing it actually fixes a memleak. Signed-off-by: Andreas Rheinhardt --- The VC-1 decoder actually does not want to init hardware acceleration in its init function; it just wants to initialize some static data during its init function for safety. It actually needs only very few of the static tables that are initialized during init; its initialization could easily be factored out. libavcodec/avcodec.c | 46 ++------------------------------------------ 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index c7a8001608..b054303afd 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -395,51 +395,8 @@ end: return ret; free_and_end: - if (avci->needs_close && avctx->codec->close) - avctx->codec->close(avctx); - - if (CONFIG_FRAME_THREAD_ENCODER && avci->frame_thread_encoder) - ff_frame_thread_encoder_free(avctx); - if (HAVE_THREADS && avci->thread_ctx) - ff_thread_free(avctx); - - if (codec->priv_class && avctx->priv_data) - av_opt_free(avctx->priv_data); - av_opt_free(avctx); - - if (av_codec_is_encoder(avctx->codec)) { -#if FF_API_CODED_FRAME -FF_DISABLE_DEPRECATION_WARNINGS - av_frame_free(&avctx->coded_frame); -FF_ENABLE_DEPRECATION_WARNINGS -#endif - av_freep(&avctx->extradata); - avctx->extradata_size = 0; - } - + avcodec_close(avctx); av_dict_free(&tmp); - av_freep(&avctx->priv_data); - if (av_codec_is_decoder(avctx->codec)) - av_freep(&avctx->subtitle_header); - -#if FF_API_OLD_ENCDEC - av_frame_free(&avci->to_free); - av_frame_free(&avci->compat_decode_frame); - av_packet_free(&avci->compat_encode_packet); -#endif - av_frame_free(&avci->buffer_frame); - av_packet_free(&avci->buffer_pkt); - av_packet_free(&avci->last_pkt_props); - av_fifo_freep(&avci->pkt_props); - - av_packet_free(&avci->ds.in_pkt); - av_frame_free(&avci->es.in_frame); - av_bsf_free(&avci->bsf); - - av_buffer_unref(&avci->pool); - av_freep(&avci); - avctx->internal = NULL; - avctx->codec = NULL; goto end; } @@ -586,6 +543,7 @@ av_cold int avcodec_close(AVCodecContext *avctx) av_freep(&avctx->priv_data); if (av_codec_is_encoder(avctx->codec)) { av_freep(&avctx->extradata); + avctx->extradata_size = 0; #if FF_API_CODED_FRAME FF_DISABLE_DEPRECATION_WARNINGS av_frame_free(&avctx->coded_frame);