From patchwork Thu Sep 2 15:34:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29957 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp393791iov; Thu, 2 Sep 2021 08:34:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRFP0c6oKkTkFdn9M/5NyWdr73iQm85Ax1mBzMF3lnzjgJHS30pna+Ps90/BbyENL9G2OH X-Received: by 2002:a05:6402:b65:: with SMTP id cb5mr4081120edb.343.1630596895466; Thu, 02 Sep 2021 08:34:55 -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 n10si2949625edx.387.2021.09.02.08.34.54; Thu, 02 Sep 2021 08:34:55 -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=nyLNvhQE; 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 1CA9968A59A; Thu, 2 Sep 2021 18:34:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2081.outbound.protection.outlook.com [40.92.89.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5C82068998C for ; Thu, 2 Sep 2021 18:34:44 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EbxlZX6qPDP3F28M9ezwa9vMc/lPTtvrHvlCAIxYK+9QuHs/7mz+zAujREVSSMAu/wL/MOSTvMAoCBTpMkj+574x79mE/Wee/X1nwQ63b8sOJjEs7IhMnOsm/Fl/AGFhhMJYlGvVWmcGNViNIQKhBIED9BZWN5FbiIK6d64PkO69TopirlEWcDOoW2bYdwSVCv/EViUN+Rcdzv2Hz/Mnt5ooB5tSUeTacsYFt2ASL1KaP2jE8TMklaLbpgibmrcZq1Duu/h4wGBA6gVh1zB5WMS2y1veJRQOMaephsRv6GpjmzAvgMrhgj3mklri7kjZW2dVN14+hB5ngtvqSNHXoA== 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=EzEjZxuJ4IUL7E1aM8SOfrUnmBllG53tlTqD9IDJbk0=; b=aUAvm82XrDOf/Q+pZs6JRX/8KiPwN6Te3xixA2DPLC43zPaduRgqW46NUz7wie4yO88PpJ8xkKHwMsttAbCU9l6he9UO25UJetnDiIiDZnznfzd2mjLTp5TzSMBjC54WljXJK1E8S70XVrsvdkGZ1uUM8dWRCUmfrQLoGk02FNMWkhQvB4eYnTJ6F7KNsEPK44RCAq8ugu47GiiXpTsYB88LTXaigmgEYYiwzlYSOYT8LFD0POspWMeCXCtSrw7TmOePHn3amZe6nIQo9MrJ+NQat11mPdor+lYVyUu7smomKgxvYoQS9dIO3Yj48iQOhOyQnVE5IcthxQ6EU8UH+g== 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=EzEjZxuJ4IUL7E1aM8SOfrUnmBllG53tlTqD9IDJbk0=; b=nyLNvhQEoYPQGZYZfRPy8tjqYpvt9qcs7YnhvFRlDwq/QmIc/AJVRgf20HbAqbvPjDbojFbLn5Q9nJ4Dz8NLWk5WHBKAKK7jwhzrdx14ooKaCg9boFKcS3/TgFkOq7a5fUbrZbhwbYAkV6cZ7oAjy20ETYBM5ZYd+GLgL9m52lqVgLp63VUh2OwEvNM94a9qPQZuhQoylgtwIW8bZ1WpUJI0BOjp4sI/kQ+Wk+3u27lxKNRcZgS+7cqIGsfcKtpW64eAHjwum5RsTh+rANsyimlDpODMJt+AxdE8cMS+fihZ9JQhelCjW0KLVWNwQZtb1e+XcNhfEVuSymXLt8FRQw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB4694.eurprd03.prod.outlook.com (2603:10a6:20b:8::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.24; Thu, 2 Sep 2021 15:34:42 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f8b5:1ef2:89b2:f8c5]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f8b5:1ef2:89b2:f8c5%7]) with mapi id 15.20.4457.024; Thu, 2 Sep 2021 15:34:42 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 2 Sep 2021 17:34:23 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 X-TMN: [F++m95veDzNvz60Vl9IkJV4CUCYJBPy3] X-ClientProxiedBy: AM3PR07CA0138.eurprd07.prod.outlook.com (2603:10a6:207:8::24) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210902153435.2571539-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM3PR07CA0138.eurprd07.prod.outlook.com (2603:10a6:207:8::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.6 via Frontend Transport; Thu, 2 Sep 2021 15:34:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9bdea8d9-4789-489d-c390-08d96e272f3e X-MS-Exchange-SLBlob-MailProps: zswcL9HXbeUxZgMf8eiMU3Scarekfq0vW/26Vw6seRWQWIp5RtUsXKs1HAxhCNpZs+qz45rnc9WWeirPydUf3tCaq5+sj41R8yJ96ILn0SPMgr/r1p0VEBWk3S6JLO+dTkVSERYiqbaPyYTlR0S10aJv/rpo/l7hD/lg+9E4D44gilMNQHaTsfIlSUOfVTtOFk9gCZN2wsTA8oSRjgbwIvZFE3m0MH1RhJBDV7BE/sAEgIQeb4MiPBk5Bx/gOScFYf49yOzItUTlJMcsOof+KIY0oyPIcM4Ucsdsww0KknGGicqHDLmcBjjCOGsB+aZkBJ3wC1fi7YsW8jISZ6yXst0YjDFSLZvT61oHKbVa5A9aZZw+h1J84Ab7RTeyThtr3nYk4NWUUkfdBIEnWgj7yaKgeqHqdU4PnhiY4B9Xgw3BXLWIDRMhU8v0z+VbZbRVUGvz7R+sYl8p2dqKZ/+AwlcJjRVAm6so2ZSbhvqjL8vH8NNADnghS+I6jNnkGdIpMk+iKL2b98M07SYX0nNHpLVii+uQzMlLNOncNhEfbpUj9bPX5lEwBqt7syhfQexC1tRU1m46R2NIu3ccnW1lLzAR2Z9XamTuMC+aODWBBFgD+VWI/+xvp85eJoj7EIScKwYygKEgOsL4ks4NJyW57yyzeeM5URnh82cf9Rq8nX6Ner+W8fk2TN0JD9j6Wadj3v5QR6DdLsybzVlz54/hGvXrTyUhQr/snidou7y/Y/A3MXVu7NtgMmZdb+rPo8QN X-MS-TrafficTypeDiagnostic: AM6PR03MB4694: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iUkPx91YI/PmdjFB7oQtjuaOnq9jRHtevRymR29R72ZIMaHkTzO6VQrbxplDX7TUgrr280Voube4szSTppN7Ev/P2Ha3P9tIHl2TCpTTiRs7uggIxgVNiKlzMtQrlxUvtPSV54nbGZevVSEUptVEhSZOs2mzXWS4eFxdi+cXiVLRXq+ieeRw5ndXEMNtfSYjnTiIBooUcdErnU6dKaUOj2A1S0nnAewy6pitGFPHHweqtNTTd/mxIFS7OqjsiFT77bKCLL1/4wDFJdqvnMUVJAv5pWLNeR4b2NnIYSXofTjEcPxUsVzLNaEQNypsyNziosPZE5U6y3aukivdYlqu63mevbvUc9H5BjBsfnlwUsEIyGzi/JB/rCFre9/yXho1gO8nQylYbfnI8zvqcBpyrIL9nlcaXskgB91UuyJ+Cp+Qi+FCzekA3E2en8Xxth+y X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: w6BA/HBadPuiWz29tDHcqPrFZN8a2Fpzestltzc6BHzHVJyrJSi9Aggj3QwoLIn81Mwmr+tM0p1OzbCOH5dXH45UFtaBYtFOk0FjtS4synFLX5s8ojeX+boJSlu2gr8oUQqM/wLOul/9bg14YgeEAw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9bdea8d9-4789-489d-c390-08d96e272f3e X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 15:34:42.7776 (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: AM6PR03MB4694 Subject: [FFmpeg-devel] [PATCH 01/13] avcodec/vp9: Do not destroy uninitialized mutexes/conditions 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: Steve Lhomme , Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: FtQxsOhmROqd Also do not destroy and reinitialize mutexes and conditions when certain input parameters change. Given that the decoder did not create these variables at all during init, uninitialized mutexes and conditions are destroyed before the very first initialization. This is undefined behaviour and certain threading implementations like pthreadGC2 crash when it is attempted. Fix this by initializing these objects once during init and freeing them in close. Reported-by: Steve Lhomme Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 874005a5ae..5c20a7ec5d 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -43,8 +43,6 @@ static void vp9_free_entries(AVCodecContext *avctx) { VP9Context *s = avctx->priv_data; if (avctx->active_thread_type & FF_THREAD_SLICE) { - pthread_mutex_destroy(&s->progress_mutex); - pthread_cond_destroy(&s->progress_cond); av_freep(&s->entries); } } @@ -66,9 +64,6 @@ static int vp9_alloc_entries(AVCodecContext *avctx, int n) { for (i = 0; i < n; i++) atomic_init(&s->entries[i], 0); - - pthread_mutex_init(&s->progress_mutex, NULL); - pthread_cond_init(&s->progress_cond, NULL); } return 0; } @@ -1252,6 +1247,12 @@ static av_cold int vp9_decode_free(AVCodecContext *avctx) free_buffers(s); vp9_free_entries(avctx); +#if HAVE_THREADS + if (avctx->active_thread_type & FF_THREAD_SLICE) { + pthread_mutex_destroy(&s->progress_mutex); + pthread_cond_destroy(&s->progress_cond); + } +#endif av_freep(&s->td); return 0; } @@ -1797,6 +1798,13 @@ static av_cold int vp9_decode_init(AVCodecContext *avctx) s->last_bpp = 0; s->s.h.filter.sharpness = -1; +#if HAVE_THREADS + if (avctx->active_thread_type & FF_THREAD_SLICE) { + pthread_mutex_init(&s->progress_mutex, NULL); + pthread_cond_init(&s->progress_cond, NULL); + } +#endif + for (int i = 0; i < 3; i++) { s->s.frames[i].tf.f = av_frame_alloc(); if (!s->s.frames[i].tf.f)