From patchwork Fri Mar 13 10:28:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 18155 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 1E77044B540 for ; Fri, 13 Mar 2020 12:30:13 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0900768B063; Fri, 13 Mar 2020 12:30:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A6EFD68B038 for ; Fri, 13 Mar 2020 12:30:05 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 1D410295747 for ; Fri, 13 Mar 2020 11:30:05 +0100 (CET) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id WOSrePUb_hXA for ; Fri, 13 Mar 2020 11:30:04 +0100 (CET) Received: from quelana.khirnov.net (unknown [IPv6:2a00:c500:61:23b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "quelana.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id AD6F8295796 for ; Fri, 13 Mar 2020 11:30:04 +0100 (CET) Received: from localhost (quelana.khirnov.net [IPv6:::1]) by quelana.khirnov.net (Postfix) with ESMTP id 09C4F2535D for ; Fri, 13 Mar 2020 11:30:04 +0100 (CET) Received: from quelana.khirnov.net ([IPv6:::1]) by localhost (quelana.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Edt5shcKz8Qi for ; Fri, 13 Mar 2020 11:30:00 +0100 (CET) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) by quelana.khirnov.net (Postfix) with ESMTP id 1C17725345 for ; Fri, 13 Mar 2020 11:30:00 +0100 (CET) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 42F4B20E0357; Fri, 13 Mar 2020 11:29:55 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 13 Mar 2020 11:28:36 +0100 Message-Id: <20200313102850.23913-4-anton@khirnov.net> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200313102850.23913-1-anton@khirnov.net> References: <20200313102850.23913-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/18] pthread_frame: do not share priv_data between multiple codec contexts 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Specifically, between the user-facing one and the first frame thread one. This is fragile and dangerous, allocate separate private data for each per-thread context. --- libavcodec/pthread_frame.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 2f68df384f..143fee238f 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -695,7 +695,7 @@ void ff_frame_thread_free(AVCodecContext *avctx, int thread_count) av_packet_unref(&p->avpkt); av_freep(&p->released_buffers); - if (i && p->avctx) { + if (p->avctx) { if (codec->priv_class) av_opt_free(p->avctx->priv_data); av_freep(&p->avctx->priv_data); @@ -805,7 +805,7 @@ int ff_frame_thread_init(AVCodecContext *avctx) copy->internal->thread_ctx = p; copy->internal->last_pkt_props = &p->avpkt; - if (i) { + if (codec->priv_data_size) { copy->priv_data = av_mallocz(codec->priv_data_size); if (!copy->priv_data) { err = AVERROR(ENOMEM); @@ -818,9 +818,11 @@ int ff_frame_thread_init(AVCodecContext *avctx) if (err < 0) goto error; } - copy->internal->is_copy = 1; } + if (i) + copy->internal->is_copy = 1; + if (codec->init) err = codec->init(copy);