From patchwork Tue Jan 31 13:16:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_Storsj=C3=B6?= X-Patchwork-Id: 40196 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp36209pzj; Tue, 31 Jan 2023 05:16:46 -0800 (PST) X-Google-Smtp-Source: AK7set9UaUy/peEv3f9SKlnUXuPV00F3s5XZ5JgxN69j5MlZUfyFdl82FU7plXhSd+pDKKhMzmP9 X-Received: by 2002:a17:907:8a13:b0:887:6c23:193f with SMTP id sc19-20020a1709078a1300b008876c23193fmr11679459ejc.44.1675171006098; Tue, 31 Jan 2023 05:16:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675171006; cv=none; d=google.com; s=arc-20160816; b=EjqSa1On/Z6tEQx63dq+OelJaNKvtwjiYDygcDfBpKctnoZktjhFiQAn0uWP8eBMLq UnAfP/GJCq0l0qt5jYqIT/dEyrf1PwScbY5ouUu0qmcXhoq+wbfaXKv3uubgRub5aWMq pYVYwYDsRPYJmlVH0qGRQ0CNByACiF4uVYFi27N0kaewh5lJpEh9YHtPp4e2qDDwdyid lAk8YwKYaVgfl26QSpC5vR/TnJEM4i2NGtohOCyhrrTTuXc+MCL8MU6nPKKyHI55agmN VtPDC3oN9odYMJq5C8P24pLMS/2T1aheZHlmXexcGBn8r6TE6pdHE03pG2WJEoJOV86i rcCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=tyun0ikFdHPGRuSNCCG4ubzfQR54FCSFA7isWJnqJAA=; b=uzm1ivAhMWs3NeldHB2iHiMOOb/6fGyJDPZxSl1IK+iw5wB2lEhK37K3qRYw/mew6T I/CrCh6ZvDbwK1+cCkEn7yRjbsTGDpr1Q5jq6XG4GI0CFYERel0bnH5hB8ZiP8yUQKJg c2OU2/uIJxPp0R530HSMnQk4lSKiWN3fZ6OWzgVkc1RCCrRU9dL4cJnZGWNY9W3jhx+v baHr0xLq9Yp4AmzaES+g+qJL22nPBsdQt3c+FAO7g99dYkNP1AXegr7JSp8dx0SGxlAb 9m+Faynu5mDIxID1kx8oLpgVGIOMLG9wu2QrnUZ8cmr/6WJF2eGAQdwdHBxQJgoPHIZn YfnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@martin-st.20210112.gappssmtp.com header.s=20210112 header.b=p2kgQObn; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 23-20020a170906011700b007c10d4bddccsi15714160eje.822.2023.01.31.05.16.45; Tue, 31 Jan 2023 05:16:46 -0800 (PST) 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=@martin-st.20210112.gappssmtp.com header.s=20210112 header.b=p2kgQObn; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ADC2E68BDC8; Tue, 31 Jan 2023 15:16:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-il1-f173.google.com (mail-il1-f173.google.com [209.85.166.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 60CBC68AF6B for ; Tue, 31 Jan 2023 15:16:37 +0200 (EET) Received: by mail-il1-f173.google.com with SMTP id u8so6428842ilq.13 for ; Tue, 31 Jan 2023 05:16:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1jEbAtWGcRSw0a4r+VL8WGHUI0t7yruyICkTFJf70m4=; b=p2kgQObn7Ql7s6JwKDH1FGPLgwKMznqPyj1CgahxjbwiEhoBxike+P1oE9ogCmjXet V3JePrfpn3sM0k8PZ80xydAfR/THLA6556GUHJwKNc7YDUFR6vf3+QhJb4WIvIB5bsfc Kgxu6OLRvDVqfPzaYUmgtQt6OtV2nHhYpo2Dyvc6KILUJDidxYUmv6FXD6RqHwJGAKUB NbtrCu8QRqF8LuN26Hp09me5n2KngBHlUjlmczNovTCRI1lVOyde2i0cK92vfJe/tIjw T8OFsjKW3SgxO/F2QMmFuQ5VX7hYVexI6akcbc9lChAEBd66vZ9cD588rblcNMhALime LueA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1jEbAtWGcRSw0a4r+VL8WGHUI0t7yruyICkTFJf70m4=; b=ITgmSK2u762r/SuH+Opa1ZLDMnk5eI7SozfY4ChWNDuSXy18IpP7MfMqy0oStij4sw 0q8LcUdpgmJmbvLTO8CcPkd1jF1GqHnabfYJw/i9+kS7VCOTqUmL7efJBCVxyQoOzLh/ 26XJQUWRinxw7cTEQ8bc7KgX977piHtYCisJabSRj5kmaHeH3STezrrhPEbndZZj7AGT TZbYufTm2fB6sLT3sGxTIttMvDunb6JCSMr1CAtkOhwkhpxqzMDNMc0hHbUSYlCUlQcW B8/YclR+Bht8m8e+VIvlm6ql/ntBXa5RBpB7pPUf/jJsiU8fTyWUINFZ+KS5JIYYyZbU cbPw== X-Gm-Message-State: AO0yUKWsTgUEg6rUnK/Fkll5NxnHN8Tx+J4TfLGAjX86ue3aFB0MvKJB c0QGOjG90J4FELPLhj95Cxo5XnntfXkkJkBM+iA= X-Received: by 2002:a05:6e02:1d8c:b0:310:b629:22c with SMTP id h12-20020a056e021d8c00b00310b629022cmr19070133ila.12.1675170995722; Tue, 31 Jan 2023 05:16:35 -0800 (PST) Received: from localhost (dsl-tkubng21-58c01c-243.dhcp.inet.fi. [88.192.28.243]) by smtp.gmail.com with ESMTPSA id g94-20020a028567000000b003a971c488cesm4860617jai.173.2023.01.31.05.16.34 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 31 Jan 2023 05:16:35 -0800 (PST) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Jan 2023 15:16:32 +0200 Message-Id: <20230131131632.87370-1-martin@martin.st> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] mfenc: Fix double frees on init errors 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: Gyan Doshi , Cameron Gutman Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: y0cnEUgienq/ Make mf_close safe to call multiple times; it currently isn't called more than once, but for clarity, make it safe to call more than once. If there are failures in ff_instantiate_mf, that function calls uninit_com_mf() on its own. Make sure that the second call to uninit_com_mf from ff_free_mf (from mf_close) is a no-op in that case. Signed-off-by: Martin Storsjö --- libavcodec/mf_utils.c | 6 ++++-- libavcodec/mfenc.c | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libavcodec/mf_utils.c b/libavcodec/mf_utils.c index 48e3a63efc..50b9fdb2c4 100644 --- a/libavcodec/mf_utils.c +++ b/libavcodec/mf_utils.c @@ -642,8 +642,10 @@ error_uninit_mf: void ff_free_mf(MFFunctions *f, IMFTransform **mft) { - if (*mft) - IMFTransform_Release(*mft); + if (!*mft) + return; + + IMFTransform_Release(*mft); *mft = NULL; uninit_com_mf(f); } diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c index f3415df10b..e3b5fb1600 100644 --- a/libavcodec/mfenc.c +++ b/libavcodec/mfenc.c @@ -1184,9 +1184,11 @@ static int mf_close(AVCodecContext *avctx) if (c->codec_api) ICodecAPI_Release(c->codec_api); + c->codec_api = NULL; if (c->async_events) IMFMediaEventGenerator_Release(c->async_events); + c->async_events = NULL; #if !HAVE_UWP if (c->library)