From patchwork Sun Sep 26 06:32:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30581 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp3042800iob; Sat, 25 Sep 2021 23:33:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHJ/C4SZ93/4jc5AAn+PT96jI91A03AVOKtc5gYSJyg7+ugwBM8tpzRBYBDtiUShL4MF1E X-Received: by 2002:a50:c006:: with SMTP id r6mr16045564edb.289.1632637988615; Sat, 25 Sep 2021 23:33:08 -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 e3si14922065ejm.466.2021.09.25.23.33.07; Sat, 25 Sep 2021 23:33:08 -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="f7m/8IBx"; 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 375F268A901; Sun, 26 Sep 2021 09:33:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-oln040092075045.outbound.protection.outlook.com [40.92.75.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2824F68A831 for ; Sun, 26 Sep 2021 09:32:57 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C8VdF7VjKR3AWTSubl8IMY3ryzl9UWUgqfiOe99FK8WGK/yeZgllGrTzT1GYEYUmf7cnhFrZs546VkcSSPgBOCzTiVBRr3l+MZiVsB45PeIhToU+SmxMGpXN7EtjDOTVHcwydmmnZgMkI2dz7E6qRQhJCwu1MfApVke4i+5kWryAr9lZdKMsCv59s9Wp5omSr5k5tp5rOt+jrqIk5W7/clO7Q6KeoS9NP0c+3YBBK0TP087tnokTAr+fPZ0zvFnz60eaQIjyCQv2Au0Ot41YzRvij/4s2wPLGBQiJDf1CPq7GzW2ui23DW5vDtKBl3VqBOpp07cnSSubOpuuSbtprA== 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=AZFvjhHyzETFT8O5vRqKUDLc4rZPBQAbUAfvMlfTwcc=; b=FCvSnb3T0qBsFg2Hb1Qp5jwvuy9YuWljLsg4ONzH4gg60BXwWUvvhQIAQicwRtvFQYlPju3ax8KTQ58sQcburpWSQp7tOQn/IlgcLaF4SzS0aHMySZ02AeQbdeLVtmGc9YNS6MaSya6akXkEI4mEkMXuyriDUpuWyYiFYuO55bxV5C8K6T3k/O2dYhXxQCrMwaik4zuZZvb4kttbpYYejmGyCLyOrUKyi95dz964CHYd/iFAwjxaucqib6YTOfwuiRE9k81Gg70DfsgMe40NhcNqPQQ6aBnYeqL2RxQ9ImOSiJ9hHqKi/V6bTNHHi8LHwTbf9xcbWYqIhmeVBVuP4g== 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=AZFvjhHyzETFT8O5vRqKUDLc4rZPBQAbUAfvMlfTwcc=; b=f7m/8IBxJ8GQLZaMdV9XwWIoRqrgZt4dAFj/XGdpd85qhlIqAGKb59stEswMo84k3YBFJh39NvUlBD5m4JSdCOhCpd+ExU2FcdEmI6UfiYpWZWuHwdcSb/1NjseuJH7dIkv3069cOLi81PGlFwLlJDqioKqctVtD2ndt8B5M+tcUPhqKunG+JG8pYXqpeYk5WJ7XaqYhILl73oy4C4jgypzUPTCC6wV94EW+sk2gvQ6G6Rtkm3JLQ/f0zvAU7itNsymJnf7Qu4NLTBn8l7JucEAhAJZFC6V7uz6bWVElWcZWNxPnAE3WOAG1C5+jS0qmTjgL48nTcOhIP+RKu1d2ug== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.16; Sun, 26 Sep 2021 06:32:55 +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.4544.021; Sun, 26 Sep 2021 06:32:55 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Sep 2021 08:32:35 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 X-TMN: [c+1Vjyi9VGKtt1+/XV882hSF3qyVdQog] X-ClientProxiedBy: FR3P281CA0006.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1d::16) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210926063240.344252-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by FR3P281CA0006.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.8 via Frontend Transport; Sun, 26 Sep 2021 06:32:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4e691f9e-a961-4ccd-0bf0-08d980b7793e X-MS-Exchange-SLBlob-MailProps: 3tYrFWTD79DYpfpsZuOR7dH2ijAywP+xwoyzJCjpTGZa5G4EqxiABoiL2ywBpt5u01hKlm+LzE/hc9d3at9YAl/Y4JoYas+Tw6ZObjmzT4zV7y4LwEpyYAmHZm0S4eO4OGnTv3Lp9oTItNJf15YO6fftMhEVlEKXcAbcMAhIZzRVoVs0VxKAK2D3TkhV4sWKHMjLGJw5xtqmY5maW5uvlao473emXVMISMhWQ3y91P+cyzsIVBLXUnT0ZLPPciEiaT1FOsxba65dEwYknjDRBNBDg5Rqs0lrF+IZZx4jwI1QQPD1IQjwImnzx3xMjjUaT0Xfo4chR7vz3G1l4Ij7mo4bjn8nvvjsZZgE+jU98IwpnzXpW/zltGpVW1E3VDjX25V6KlOrqkPdKDPv4oyx0vtjDk23YGr/YnqXzr/goN/fETlztMw6RGpYB8AEzGo+luuVzukYDQSri+mkejWWmhEan2Hwoh/fNLX2+h5M+dRhV48w0hFf8XiNm7GGq74wUNMtIo5fd2XNSqE0udqkFk+S72I9cqpsqbJIFv6BR6STFnRYR958nHnYyUPXD0LKReHyUh4asU8Z7dKnkTZK022E1NK3JUn8WzQeCfPUKjwI0b/NnBP3mO18U6niDrxU+i9vL7hcFctvry0qjpBaVtQt8mNB0I7j4PtNZ4uMZHRF15FHjfF7G3Xzp+1Qct3PZHB0oJyct2VlCHKQKxaFA+XuczXch8BuA9betEP/DN6SQpwJ7Z50eFuqOPj7vEoi4QOpixOKw3i/fVkx4WilKD+BxC+lf9Uv X-MS-TrafficTypeDiagnostic: AM7PR03MB6660: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hz4mSS8GjrwtFt3ywP5EuLTq1lAvcDy1Csg7vN06ALWCVcJc2ME5nGG7SbQwg7uCjVVVwnFT2ke7j19vb5dlbLn2MXcZ2DE4ndSej4L8xqyb8PXWNz+nqleRPQY2e895mEM8Ukpo+qpiA7M/8K82LcA0QagMEgam+QMEMw19RmMa0KXIbAs1oQiV+bb4mrnh4cZ15nWsAWUrMlGEn+aRHwtjIASpp5hYy5iUHYnJqaQNvl7VuwvX6GSGoPFx7HkUFxyMfMhIvn1RQtiBxPo4DWmGCJYxZewvyXHi96qkX7IF6U3fUTDjO+Gw0BVqtFylJEYG9YQfpSOPJFVMM9m78NQ2rBR/JpG1rPT1xI2yWJTzizdUx94efnfD9fmpzkpql6fJSiLbSrYHGQhtwlq0LvizxsEBPo7ec6KrRSCvOxmjNi0cza6cIIUcR9sXLy2F X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fOTXvVk3CPn6B4GynBZ6mKOZX4vXbxqcyOcWYXNVkcKau+qWGJ2FfP/NRvBTQbNUSVkjCnC4zRtCu6LLyVYRCrU30rIQTltVK/73kzD13zWyFOIKVcRnF2Cbz4IAa67QgjVmXa62mQxsIOP4xrYcPw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e691f9e-a961-4ccd-0bf0-08d980b7793e X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2021 06:32:55.4301 (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: AM7PR03MB6660 Subject: [FFmpeg-devel] [PATCH 1/6] avcodec/qsvenc: Fix leak and crash when encoding H.264 due to A53_CC 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: h3f75tOCuYZS Since commit 3bbe0c210b05fc6fbd7b1d4bbd8479db7f2cf957, the Payloads array of every QSVFrame leaks as soon as the frame is reused; the leak is small and not very noticeable, but if there is an attempt to use said array the ensuing crash is much more noticeable. This happens when encoding H.264 with A53 CC side data. Furthermore, if said array can not be allocated at all, an AVFrame leaks. Fix all of this by not allocating the array separately at all; put it in QSVFrame instead and restore the Payloads array upon reusing the frame. Finally, use av_freep() instead of av_free() to free the payload entries. Signed-off-by: Andreas Rheinhardt --- libavcodec/qsv_internal.h | 2 ++ libavcodec/qsvenc.c | 10 +++------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h index 8090b748b3..fe9d5319c4 100644 --- a/libavcodec/qsv_internal.h +++ b/libavcodec/qsv_internal.h @@ -76,6 +76,8 @@ typedef struct QSVFrame { mfxExtDecodedFrameInfo dec_info; mfxExtBuffer *ext_param; + mfxPayload *payloads[QSV_MAX_ENC_PAYLOAD]; ///< used for enc_ctrl.Payload + int queued; int used; diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 06f55604b5..66f79bb021 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -1259,7 +1259,7 @@ static void free_encoder_ctrl_payloads(mfxEncodeCtrl* enc_ctrl) if (enc_ctrl) { int i; for (i = 0; i < enc_ctrl->NumPayload && i < QSV_MAX_ENC_PAYLOAD; i++) { - av_free(enc_ctrl->Payload[i]); + av_freep(&enc_ctrl->Payload[i]); } enc_ctrl->NumPayload = 0; } @@ -1273,6 +1273,7 @@ static void clear_unused_frames(QSVEncContext *q) free_encoder_ctrl_payloads(&cur->enc_ctrl); //do not reuse enc_ctrl from previous frame memset(&cur->enc_ctrl, 0, sizeof(cur->enc_ctrl)); + cur->enc_ctrl.Payload = cur->payloads; if (cur->frame->format == AV_PIX_FMT_QSV) { av_frame_unref(cur->frame); } @@ -1309,11 +1310,7 @@ static int get_free_frame(QSVEncContext *q, QSVFrame **f) av_freep(&frame); return AVERROR(ENOMEM); } - frame->enc_ctrl.Payload = av_mallocz(sizeof(mfxPayload*) * QSV_MAX_ENC_PAYLOAD); - if (!frame->enc_ctrl.Payload) { - av_freep(&frame); - return AVERROR(ENOMEM); - } + frame->enc_ctrl.Payload = frame->payloads; *last = frame; *f = frame; @@ -1615,7 +1612,6 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q) while (cur) { q->work_frames = cur->next; av_frame_free(&cur->frame); - av_free(cur->enc_ctrl.Payload); av_freep(&cur); cur = q->work_frames; } From patchwork Sun Sep 26 06:40: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: 30586 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp3046398iob; Sat, 25 Sep 2021 23:40:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYBEmqNIDR6fHYDKC4q22OyUdKtXZI8IBQAE34n+yEF3iwFa3Agk727cCxMxTchf5mjTZr X-Received: by 2002:a17:906:ae83:: with SMTP id md3mr9939566ejb.84.1632638446911; Sat, 25 Sep 2021 23:40:46 -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 x15si5812048ede.404.2021.09.25.23.40.46; Sat, 25 Sep 2021 23:40:46 -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=enRPqjMn; 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 E33D168A6A1; Sun, 26 Sep 2021 09:40:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-oln040092070030.outbound.protection.outlook.com [40.92.70.30]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4E04468A6A1 for ; Sun, 26 Sep 2021 09:40:37 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QEl4tEMqj6jRQmftOQ8QUfl7Blnx8iB38PxfWhI6Nz8pNanf97IgQobQvzXfGxhvPDO7SKJfwwPH/5Ch+T4Ywr0Fg8nnkuw8mH7Rm/3vz6/a5OlIJm28+PXC55AfkByz00igdaeTTbv0wMxQiLAZK7Y3JNELr19obkMS2d2wRQaJJRqRDgZ4w9QO0R3JNbRONOFpPFbRknZPhglsxzhfvch73SAxdFMLxVTxsyLnq3D8dBaMxffsXJFQu0Rwiw4I59PaEyPQrfQBnK2/m83OH8XNqYThP/u9zMig7RDqlAD2EUZK/xp9QnigHqIgOIyiFtGPWXHBIfX/AOEsVJF73g== 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=unPTq4WUo7ADEa2abxhC7/cZbPo9BIwkMKUnTxrsy14=; b=lGvDdJglsd+j9/5qf0jvRcPwBSVW2Q1WCuxOzJAphbI4HPCikXVOLnyxNF29TXujrlAU1wvKXpeOJcBk2bCTum0BUmpCDnBKc9VwxiFrJcvLV1SOjZKbq6r2aRUmqm2iGCTtsRSpNxk4t03cBp+zq8SsxaHTidPoJWRqsWie4q0zWB7NZb5pR4YiK8BMxJEWQDwjTi/3TkNUT2/G7H9W9adlqyvK+7HMGxFwrnMA6lJWOWNRG10opH+Z8y02aPU2YXBx8HLtz8q51XbQw2hfjwA7aioXPnS/f8SuKrY2d5N8E7QjDrYPIBCgaGn1F8IVxjNruneFAzUrcnm+tw6fsg== 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=unPTq4WUo7ADEa2abxhC7/cZbPo9BIwkMKUnTxrsy14=; b=enRPqjMn/zAgrS85g3tZsJ/uiUGxshcXQs7xZ2Ab6aesGt1iiyMG9uwWy54NcD9YhiXdrsYBHZfMZxHSk3HV0NYypzlF6Xw9rccgadNRGSyWgyAkBcG3opXJmhTwxELKP/WTMxF9X7qes73Yu1yJCiAnaIxyEgvy7m2WhyhdvTs/Q2aK/WgwD7NLOf881eUZtywjubS0CHZ9BX1OuoelMU6W+HANKSdq2oaII1CRTeyscFc6RRK4nZ5TE75Bepg6ViZUjuvrksghYGSiVG47BHwsAM0HXF5xwuFpzHlPkvcqMyYageWmA8mptlR7XRXm7FvZhJUfoCox5ylWyx0cMA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3768.eurprd03.prod.outlook.com (2603:10a6:209:37::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.16; Sun, 26 Sep 2021 06:40:35 +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.4544.021; Sun, 26 Sep 2021 06:40:35 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Sep 2021 08:40:23 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [tm1fz5b9yvom3Sv3MHNF9FB9GUfEeUK+] X-ClientProxiedBy: AM4PR0302CA0010.eurprd03.prod.outlook.com (2603:10a6:205:2::23) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210926064027.344398-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM4PR0302CA0010.eurprd03.prod.outlook.com (2603:10a6:205:2::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.14 via Frontend Transport; Sun, 26 Sep 2021 06:40:35 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b508afe9-77ec-4ce8-9b42-08d980b88bb2 X-MS-Exchange-SLBlob-MailProps: f36zkjAOy3U/DR4NyBZ4rqa2NklQwVm3uwq23uRFxtyZspCwSXAylhSIm5dPtyJAzavpH3+xVughV2WUrQYLnM8Ug85zQ+Q9zWYeoVu2j+W02/k8vgeAPUHjQX3FPsZQBtrQDrg9coa/4MxYCtzvsxjXNuoN9SIbZovK5fgqZqC4wZzPMjGNNyZUE6f2mdF0G+kZkzCV2AYK7ubJ++Y7tFLrhsct6OcPQJSjm/PWFTbb2X4vY/yVHmHBOJ46MYQDE3F7RzOW9t8CJHgCXJzCV+HDgOnTh7qC2HsQg0lhahUNcySM7ysTijhV4QVXQX/1SoSIJY3jxuvWAE9+A+2s0VXLVPudaH4hrROl8QuDkvbBBX0kQBIWl3e6pUHh+eNmv4gG7LsdcTurQ79/BlYo0KcV2I/J2gGkwIWZQcksbldTLodeDMg40pEbt/czoMTyGLcnKfHyr2zBEYQAPZ4GsIK52ANQCLFpHTF66HL7K+4scupZb3uqh/q+/A+LxUeFNUD8SEOxC0MiQCGlDIV1HjW0PgShl8niz2Kc+7TTj1ylWJVK2hirO2g6d+Rpo9rePeAmZJtZ4YlaHswe8Kru88aX3JnOfyEGOIyiHaqCWRc7t0jQ+gn8Z9Ob4TkIND2HeWGGuZZki50QFSb+Df+Uo93xwsJp+1xlP5BoIBdeV69qL4adomeVbBFT9pHNDt4YqEr0B9JT6sf/33lQmoDAc4r9P2MA3LmvUyxmuAixa88= X-MS-TrafficTypeDiagnostic: AM6PR03MB3768: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: whyiA8xHibUq0+y1HyrhjPzuRy3pFTZWHmzebUx9B0TYe4aY1y+mwGzypKy0xNJGRx5UarYLl/I2DUHZcMNrNt/h6RIYTP9sFpTamXg0OJDOqneS77H4Q1zsumdYTlBK/t14qs7vFS03D+ukvfi6DI9MSYcCMPYpmbq48Pe/ra1VbkBvWtoJd0kCU9tDRiKFK6IRT9CxTIQ+tqjufexvN3vbZyiyh1f55LvPHSFIlyO40vvAVfW8EmsMyYRQwCMTF9dbp8nkbUPiyWKFaz/i4HEZ3nf5A000AswjTXMREMhIrNSrEGyzQ/8p3k7HqFy0CYRJBJHvLB9MFnd+nPfqeej3QPRzCzD/IK8RyWM5ZFPxDVN+Lkk0HRSi+Hwg4gHlKz8dM+Em6lZx5lUiImFIt+PzEUQb935acsdqNIqXaK3tGM/sF1aOXHWR7cfgWriX X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: m+TyZrd16MFgAB4WyNKpvQsUv6uXD+zh6v6o0rQ7vwauJ7nzVfFYoJCUIarjCsgrX7MKsVJZgrBBsPL6ZL9cKoVhGFH+yzdEO2B5IUKg3nBs8lzk6jeGg7SjKODnW2MK4OAK/Isyb4I3CILldbF/mg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b508afe9-77ec-4ce8-9b42-08d980b88bb2 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2021 06:40:35.7822 (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: AM6PR03MB3768 Subject: [FFmpeg-devel] [PATCH 2/6] avcodec/qsvenc: Fix leak of A53 data 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: phRy9JCgNjIL Up until now, it has only been freed when the QSVFrame is reused, so that the last one contained in it leaked at the end. Signed-off-by: Andreas Rheinhardt --- libavcodec/qsvenc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 66f79bb021..e5d09752cb 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -1612,6 +1612,7 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q) while (cur) { q->work_frames = cur->next; av_frame_free(&cur->frame); + free_encoder_ctrl_payloads(&cur->enc_ctrl); av_freep(&cur); cur = q->work_frames; } From patchwork Sun Sep 26 06:40:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30582 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp3046462iob; Sat, 25 Sep 2021 23:40:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQKxTtGNn5ERV50Wmgk92tozgBV/75qXZIA7XnPAArBrYboeNk4VlU4nPCufxSiEn4Y0mm X-Received: by 2002:a17:906:9747:: with SMTP id o7mr20461558ejy.486.1632638455858; Sat, 25 Sep 2021 23:40: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 m9si16774823ejj.143.2021.09.25.23.40.55; Sat, 25 Sep 2021 23:40: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=imnLjrsT; 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 0CEEB68A936; Sun, 26 Sep 2021 09:40:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-oln040092070041.outbound.protection.outlook.com [40.92.70.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 71F8B68A923 for ; Sun, 26 Sep 2021 09:40:45 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mPx17ljEyGcoK/2aYD8VJ/eVMdOThVjGMJayzFbTfnpOhl4h5ZuAAiCEMqoQBJ1Vmvq7qZiigB5zIyc5EFyXnCRZkPQ6gLy/37uaPNjnKCq24GMTsgNUvwnp7Zbk/zg4csGCiEENT3tTJbDsW2ziCoKhctM959C97NWDpZTvL7lc5GEl2CKxiYYr5fI2NfalvzF4t1JWPAjN9xQTb2pNGp6zl6AcISTUFMGMmsjw4oxtcdKb2lsHPsndMeUDU5hPRlPqj5S6d777/ko4ybX0n07QBBZleyPy6CUMhB76wAk+llvkmZVs+CXsjsojWBg1Ne7Mgk96Xrn88YQqRVbphg== 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=4IwQNttlcj/j/tjbVgXzEHfvzK64SfzFgJBggOefItM=; b=JYqPHBU9mGu4EshqrDqHQST99S0EojEcoyUTSCw8j3/2m2hYhZuyDl2N6eCABo/DNQCnLlr+Q7JXM6XX9kaFuLYcjYmQOM7BjF8Q6fYE2GfKsuC/0zwU+4AfKWIpcUAkgqdrBlWfRpUN7diAWCnDGLO6pB3uoZNNqqvnnTsCwwXCSa3e/FBPG3gEi3W7gaSVY35NqV9gWsnUDbyC7PhvTBsG36Fzo86n/snll7MIu7e6HQPCcM6PINWDGKXAwf5KkFbHdhMpWFryxEct6NkHfMWs62rqE878F6In+R1yhR4m2wehDIJ+hVt9sPIf5ZcTFu1/I0FAsTypaLE670FwUw== 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=4IwQNttlcj/j/tjbVgXzEHfvzK64SfzFgJBggOefItM=; b=imnLjrsTXErxxd51Xi1UegvD+agrfRiA1HCMQ7SIgfGs6t9+dHhyXbZl5pY7Z/vyGa7RS1wj9ELTG370s1O0Ta8v3ZnD7RJPjOXmANIb78yYu0M/XwcxAjYRd7mubeAPE77WXhfXhdLzBrn1QjtfTEIRf8G1lI1DcFzqbog7G8HhD74K0YgDd2YsgDhhmxUhV3p9WJG9ArDaHhzVo8kFTf3NBN2e0Lf9Uvyu77jf8JWQlH2wYqZ/CoT7tf5K7xOXYRITnZP52TZPn/SKy2Y225XjEGsBUYQZ9xzXmARin4lY+WquOcXjgCjE3p1qcqfp6nNiMpxXSFK+cL2LYQZqqQ== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3768.eurprd03.prod.outlook.com (2603:10a6:209:37::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.16; Sun, 26 Sep 2021 06:40:44 +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.4544.021; Sun, 26 Sep 2021 06:40:44 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Sep 2021 08:40:24 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [3UegiZa3ZrHaNzGArjkf6kDaQKNKgCLo] X-ClientProxiedBy: AM4PR0302CA0010.eurprd03.prod.outlook.com (2603:10a6:205:2::23) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210926064027.344398-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM4PR0302CA0010.eurprd03.prod.outlook.com (2603:10a6:205:2::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.14 via Frontend Transport; Sun, 26 Sep 2021 06:40:43 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: afca4de4-b2dc-4a67-9d1d-08d980b890c6 X-MS-Exchange-SLBlob-MailProps: q+fD6XS3/UIAJF/k4bgfswNNO8o0J1y91aBk+L/y6h+6Rj/skk2rbdQglmIQmQT215XUMK3f9BrFMF6mFCvmNcAvYEdK4O5LaR/AbymojYldmvmG3nvuBmHtnqu4p6PW1HJ6pPkXoG14Rb4jCIzbQK3s+UxDYwLe7/bAQHQf41Q3ZxePIiIbIJtt1wAVfnWlzl3Qetuum+OkEhU6xOHX5XowjpXRgBxfip0Dur3In0luhU12MFZkCP4Q3eF0jBAkRqb1azOKkcuKWWUBXmFeX0PEG6pMz/xI9llAEVJdEa/E+KGKUQEfqwN9paBPTlsIiHCwD+7TizvktsU8TjOl1mF46cpBMW9mMrFhoWhej6X3NX70w8fHMmYPvRRXoSFIYt8SrbZdVCl2zYC6w5+pHxR8rW+ZdfiyTez04FRdDmmHNi8QgkavvI9vHYo6WtImD5FgD4Ba/KRoZ9wS8BKMVsNhg2jX/5kWB12KeUb61pRDZzQIk/s3mAFTs1hY8Ntt6/DIEDOPwm8DtN3/Zmjdf0lD3GdTA1/xgU1FzgpHJXcQ8yESnVnmfXLz1uJ+UnKWg+afEJVybDPGExWQaOOuCyAKPlQy7sXgAJdtD4flvobql4fbxvENOzuh3bKbKs6kaNPbz1hmhqi2cch/IGOdNCLmmcmIc2Y5peUQU6rU/Nn9y28KCyvGB5A+4GNpDHO8/w4UtZOTG3a8Ev6PEWGnJg== X-MS-TrafficTypeDiagnostic: AM6PR03MB3768: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HK/f/uHwzts8oJsKcGzbAyX8eZYVViyT5666aiLCKMgDBTb4UXiOAR8OKcLPhuMQ6tUnJ+B6Flg71oQqkTEQ2MndQLCnjAPiYCx8zyc966PKxGb72hU4z7Wkffd1SM8mpnsVmUulGZZtc0LYyevE1b6/O/phFYZTVBcI0KM5t/wchMOKi8uOYgknom3QAO71sPzjcCo5opU+Dvqp/m9EMueY0Wp+IB1ByYX5qFzDQjvKuMhEkExn4m2wvru8Vrxkr8fK5k+K9SvSVh7GEXSLDnNGk0a10euneypZJOLoaXMq2QJzHupH5klNpzYJdvKE43DJ+FmTWqpO6MLEvjG6laAE/ENS+LlTD0QH6xe05CD+aT7NDWy/r6ktB6fM9FeIG1gZa5pOWb1A5ZWkD2fAzGYGagePr3zWYftMSG9FcxFO1aZvb6G6j/xYjl1R+5Sw X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Q+QOOuh8tykJEPpOfTXDGUSmdDLf3OSWIrT3dJZnlhe2FP1f4Qk1r0vfQA/jcPHTdLagl5rEZj0g//rXLyQYT3uiUa8MczovE4D0JgK1ws4THuhtovSgPgZAH5zKyxjUA18BBtuHqHuGNz1fCCfewA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: afca4de4-b2dc-4a67-9d1d-08d980b890c6 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2021 06:40:44.2840 (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: AM6PR03MB3768 Subject: [FFmpeg-devel] [PATCH 3/6] avcodec/qsvenc: Properly flush the FIFO on close 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: EOMab1WqBHBw Freeing the new H.264 specific fields has been forgotten. (This leak only appears in case the encoder has not been completely drained.) Signed-off-by: Andreas Rheinhardt --- libavcodec/qsvenc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index e5d09752cb..26a94cd419 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -1626,6 +1626,14 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q) av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL); av_fifo_generic_read(q->async_fifo, &bs, sizeof(bs), NULL); +#if QSV_VERSION_ATLEAST(1, 26) + if (avctx->codec_id == AV_CODEC_ID_H264) { + mfxExtBuffer **enc_buf = bs->ExtParam; + mfxExtAVCEncodedFrameInfo *enc_info = (mfxExtAVCEncodedFrameInfo *)(*bs->ExtParam); + av_freep(&enc_info); + av_freep(&enc_buf); + } +#endif av_freep(&sync); av_freep(&bs); av_packet_unref(&pkt); From patchwork Sun Sep 26 06:40:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30585 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp3046559iob; Sat, 25 Sep 2021 23:41:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoV7xLW3sBtZrx31UFKpMQGKnrGePijaETxu8ERHRMHjs6N/P6nmMeTAgZIm+SFNYFHMpU X-Received: by 2002:aa7:c74c:: with SMTP id c12mr16009521eds.87.1632638465403; Sat, 25 Sep 2021 23:41:05 -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 bf24si14537616edb.7.2021.09.25.23.41.05; Sat, 25 Sep 2021 23:41:05 -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=C5pR65cP; 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 F180168A94E; Sun, 26 Sep 2021 09:40:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-oln040092070041.outbound.protection.outlook.com [40.92.70.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 885E968A943 for ; Sun, 26 Sep 2021 09:40:50 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l9yL9D3kK6hYMDb/5pFXcn3cOgEEWr3RdQSgNt9mop0ea6wByvCZnQEgYk9nBeB6N+ZdqgPRDyFXy5D6IrsBYt9IBV8QHAPkdsU4sZO9YK0MuO5EFRzCwOfl0tVl6DjKOfw4OEmygHnSx48ajfvQHS8KLIlIRyxgXOiLX+h9GOli4NZ0jTN7j4jzGqLS1+W684qfAACxmBFYOgGCJNHScJAvSnessh+SelmsAj5fnHjGMEXa+zYNLPiUrMwHnCQsznizrd7MKqdGQYbsBfPIUpQIyAim0A3m6LoHx7MY9rGQYq4UwXH5sfciU6aQQWj6pqmkc9HZirDBhk6GVq7Lrg== 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=+rExv4ZYtVhmgZbvKscQKyTavE/xSNSkRalwbBXldEs=; b=O28j7by/hMmyMKH3DREBrAO1gYIbxxaNn9g866BVgLCoPAhaOF83gJkcvmyQJlXRPgJRDHBkIKCaJ+nf9e6IWS5fRm8NYgAplhUA0f6vYFjZ066tzW+PkRpwWwSmbPBEFJILyqiB3S2rPtWZHCIAQDRUrlbrQnE63Th10Jge4LtzHHjcW+FBG97Ppm2FGW6XZEBRm+bXO6k+SviWXcwLs99UgWZzQlKLi6XAKTIae16cJq8KdCAr3IdknAud+vxNQYIOxzE7lUedG7VU6AL/p/wuegZjSeWms5IwZIb4uizEFBjc8g+/fynLAs90MKVPYcsnGo2hpCUYguZS0UAXrg== 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=+rExv4ZYtVhmgZbvKscQKyTavE/xSNSkRalwbBXldEs=; b=C5pR65cPifqf+lUqCc2y/St8oMXVW2Ml3Y8E+npZuABw5Zp0c7MQ0xeKCw75Xnmguf0CLXe459Ha+tqUPyj+9K0LPyV+jrhfncpPRTkCf7unnfCHT0rJ5EaBcHykvP11UeHVq1EEC9swVoNf/Dn7q1slCsZAzeiS2rghA92M+JKQYS9vBfhcs5XVQH73efq19B1ADxxoWhBRWtuxfshJ3MCTPwwyAW7A/ksBBJzV4R118Qco6i2McqWCJmS3+lv7lPtK7f+XD/iJSbRvvm67kRgh+wjua48AlUKnybsJOoH2ILfLWXRvqB/O0u00DSAKyy8T3zzDZqq3K4TgSZmx8g== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3768.eurprd03.prod.outlook.com (2603:10a6:209:37::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.16; Sun, 26 Sep 2021 06:40:47 +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.4544.021; Sun, 26 Sep 2021 06:40:47 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Sep 2021 08:40:25 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [tntyimkDkX8sWNaGgZyS1BFxOFLZlkcM] X-ClientProxiedBy: AM4PR0302CA0010.eurprd03.prod.outlook.com (2603:10a6:205:2::23) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210926064027.344398-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM4PR0302CA0010.eurprd03.prod.outlook.com (2603:10a6:205:2::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.14 via Frontend Transport; Sun, 26 Sep 2021 06:40:47 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7ca966b1-ae1e-45a3-a77f-08d980b892af X-MS-Exchange-SLBlob-MailProps: q+fD6XS3/UIAJF/k4bgfswNNO8o0J1y9ephhUD51wECJIISOVB5iKKgxsE6d80ZlYH0BELZz39SpEU8p5669O7HPmkDSZqvu66XXGGduLxjrTvRhNflQXj3EfkW0Q38jPrY6eA++t59HVgqwQC3Y07/G2xCeW4lU1Z78SblK1vmH332Kt8hibO1YbRcowiwLI/4F94fOWO7k33aFl5w040z/CQSdFeAGaP/qUcdfZt228oQICqCjkmyP8M3+D0La/MVgzDXxk6lJlYctdLtLSf52wEeUidQGENKlbxlrKtom50TckVY+gQiQHzTUuXnCfM4zcKz9Z6p+psM7/o8Ey7usZAzJiHAMDkWB3Sv6KQb1/F8NSYH3DgCDHYkbXTZEH5k4cC58EX/6s/ObNzeb9oAJ1dC4AfKFLocMR3li29vJtptKohvWBYf0by4LnKQn0fwWMD0FFCDWIIIW/xuAYP9quAREBkJrv8i7hwQq40nBGbRsEgw4Ldwvv5VJLj/EaDCPipjecCAyLtS2tvmpES562SodRQX+oi42cdCmQPUZhjtsBtoGk//m6CZy1OMVFT5UILt/hEGUW6kah0MT1ZgbndJza43MnrJ4oC0TfLg6Ugi/wgaeDZKlyPh96+zSvjIhmkLoPYE2CyvXKgDFKqi0CGYV1zyeBM+mrsx6NT4Gpq9BIDy+Xg2H6n/kOX9+OayX68Tftv67a+otjnExaQ== X-MS-TrafficTypeDiagnostic: AM6PR03MB3768: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cofICdwwktNYG8Wfx0oDtRUAYb3YbpCCRd9gYPtZrqAsFtMXEVuUg5wuuTBO5Aj7uoCthyDh4ASdTBJJlgiVgLMVRbjVsxzA5eDqeSumU6rBnPtHQExSaRmRKXHmDexenvZikVSZLyLThg7IMljVznAdfece8sl4YkYKPfpdbguHDY5clVWYbCzPKtdVUt8uhM/CrBGqjARFGg5TssUW8A7kNrNpiZGu1T6eHwQNNum3VkfO6mztmkVK0GEWKAF+7C4mpvj6DFW3zBRvRqBQ15RIndR6XOQSqTjCjSNeVWpOBZXPlmEvMrhQb8V6ZNT7vle53/YCrpaIkOkapOOW9KYjEl87zNEHMAj7x+d8T1NGoA7XQkfgCVd1u4RHkq6RAndcV8zgFwT+cXKsoAFYWSV3y29+NW7+MbC6fQ2R7fZ3xvACEj9BKihjK8iRlAnQ X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: adkSNFRhk7nihRkRgztoYFUjR45DtF7lem2pea8b5RZ8yOt53yEe8Sogoo0moebgjMrVCzljGv76nMDoA+J1s2uMBIn3EJAUxW/TjRe33ecTFVfnS91fnkqhWZqweDdwEJIN++vKTZpO4gqHwvjcbA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7ca966b1-ae1e-45a3-a77f-08d980b892af X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2021 06:40:47.5955 (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: AM6PR03MB3768 Subject: [FFmpeg-devel] [PATCH 4/6] avcodec/qsvenc: Combine multiple allocations 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: VVsKuUQ6xgMX It makes the cleanup code smaller (and reduces the amount of allocations). Signed-off-by: Andreas Rheinhardt --- Better naming suggestions for the structures welcome. One could also stop using an av_fifo altogether and use an ordinary array (that is only allocated once) with FIFO semantics. Or one could combine the AVPacket and the pointer to the new structure to one structure, so that one can read and write it from/to the FIFO in one call. libavcodec/qsvenc.c | 111 ++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 65 deletions(-) diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index 26a94cd419..1650d89a17 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -111,6 +111,19 @@ static const struct { #endif }; +typedef struct QSVTmp { + mfxBitstream bs; + mfxSyncPoint sync; +} QSVTmp; + +#if QSV_VERSION_ATLEAST(1, 26) +typedef struct QSVH264Tmp { + QSVTmp common; + mfxExtAVCEncodedFrameInfo enc_info; + mfxExtBuffer *enc_buf; +} QSVH264Tmp; +#endif + static const char *print_ratecontrol(mfxU16 rc_mode) { int i; @@ -1110,7 +1123,7 @@ static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q) static inline unsigned int qsv_fifo_item_size(void) { - return sizeof(AVPacket) + sizeof(mfxSyncPoint*) + sizeof(mfxBitstream*); + return sizeof(AVPacket) + sizeof(QSVTmp*); } static inline unsigned int qsv_fifo_size(const AVFifoBuffer* fifo) @@ -1414,16 +1427,12 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q, const AVFrame *frame) { AVPacket new_pkt = { 0 }; - mfxBitstream *bs = NULL; -#if QSV_VERSION_ATLEAST(1, 26) - mfxExtAVCEncodedFrameInfo *enc_info = NULL; - mfxExtBuffer **enc_buf = NULL; -#endif + QSVTmp *tmp_struct; mfxFrameSurface1 *surf = NULL; - mfxSyncPoint *sync = NULL; QSVFrame *qsv_frame = NULL; mfxEncodeCtrl* enc_ctrl = NULL; + size_t alloc_size; int ret; if (frame) { @@ -1443,34 +1452,36 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q, enc_ctrl->FrameType |= MFX_FRAMETYPE_IDR; } } - ret = av_new_packet(&new_pkt, q->packet_size); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Error allocating the output packet\n"); return ret; } - - bs = av_mallocz(sizeof(*bs)); - if (!bs) - goto nomem; - bs->Data = new_pkt.data; - bs->MaxLength = new_pkt.size; + alloc_size = sizeof(QSVTmp); +#if QSV_VERSION_ATLEAST(1, 26) + if (avctx->codec_id == AV_CODEC_ID_H264) + alloc_size = sizeof(QSVH264Tmp); +#endif + tmp_struct = av_mallocz(alloc_size); + if (!tmp_struct) { + ret = AVERROR(ENOMEM); + goto free; + } + tmp_struct->bs.Data = new_pkt.data; + tmp_struct->bs.MaxLength = new_pkt.size; #if QSV_VERSION_ATLEAST(1, 26) if (avctx->codec_id == AV_CODEC_ID_H264) { - enc_info = av_mallocz(sizeof(*enc_info)); - if (!enc_info) - goto nomem; + QSVH264Tmp *const h264_tmp_struct = (QSVH264Tmp*)tmp_struct; + mfxExtAVCEncodedFrameInfo *const enc_info = &h264_tmp_struct->enc_info; + mfxExtBuffer **const enc_buf = &h264_tmp_struct->enc_buf; enc_info->Header.BufferId = MFX_EXTBUFF_ENCODED_FRAME_INFO; enc_info->Header.BufferSz = sizeof (*enc_info); - bs->NumExtParam = 1; - enc_buf = av_mallocz(sizeof(mfxExtBuffer *)); - if (!enc_buf) - goto nomem; + tmp_struct->bs.NumExtParam = 1; enc_buf[0] = (mfxExtBuffer *)enc_info; - bs->ExtParam = enc_buf; + tmp_struct->bs.ExtParam = enc_buf; } #endif @@ -1478,12 +1489,9 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q, q->set_encode_ctrl_cb(avctx, frame, &qsv_frame->enc_ctrl); } - sync = av_mallocz(sizeof(*sync)); - if (!sync) - goto nomem; - do { - ret = MFXVideoENCODE_EncodeFrameAsync(q->session, enc_ctrl, surf, bs, sync); + ret = MFXVideoENCODE_EncodeFrameAsync(q->session, enc_ctrl, surf, + &tmp_struct->bs, &tmp_struct->sync); if (ret == MFX_WRN_DEVICE_BUSY) av_usleep(500); } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_WRN_IN_EXECUTION); @@ -1502,27 +1510,16 @@ static int encode_frame(AVCodecContext *avctx, QSVEncContext *q, ret = 0; - if (*sync) { + if (tmp_struct->sync) { av_fifo_generic_write(q->async_fifo, &new_pkt, sizeof(new_pkt), NULL); - av_fifo_generic_write(q->async_fifo, &sync, sizeof(sync), NULL); - av_fifo_generic_write(q->async_fifo, &bs, sizeof(bs), NULL); + av_fifo_generic_write(q->async_fifo, &tmp_struct, sizeof(tmp_struct), NULL); } else { free: - av_freep(&sync); + av_freep(&tmp_struct); av_packet_unref(&new_pkt); - av_freep(&bs); -#if QSV_VERSION_ATLEAST(1, 26) - if (avctx->codec_id == AV_CODEC_ID_H264) { - av_freep(&enc_info); - av_freep(&enc_buf); - } -#endif } return ret; -nomem: - ret = AVERROR(ENOMEM); - goto free; } int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q, @@ -1537,20 +1534,19 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q, if ((qsv_fifo_size(q->async_fifo) >= q->async_depth) || (!frame && av_fifo_size(q->async_fifo))) { AVPacket new_pkt; + QSVTmp *tmp_struct; mfxBitstream *bs; - mfxSyncPoint *sync; #if QSV_VERSION_ATLEAST(1, 26) mfxExtAVCEncodedFrameInfo *enc_info; - mfxExtBuffer **enc_buf; #endif enum AVPictureType pict_type; av_fifo_generic_read(q->async_fifo, &new_pkt, sizeof(new_pkt), NULL); - av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL); - av_fifo_generic_read(q->async_fifo, &bs, sizeof(bs), NULL); + av_fifo_generic_read(q->async_fifo, &tmp_struct, sizeof(tmp_struct), NULL); + bs = &tmp_struct->bs; do { - ret = MFXVideoCORE_SyncOperation(q->session, *sync, 1000); + ret = MFXVideoCORE_SyncOperation(q->session, tmp_struct->sync, 1000); } while (ret == MFX_WRN_IN_EXECUTION); new_pkt.dts = av_rescale_q(bs->DecodeTimeStamp, (AVRational){1, 90000}, avctx->time_base); @@ -1576,16 +1572,12 @@ int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q, #if QSV_VERSION_ATLEAST(1, 26) if (avctx->codec_id == AV_CODEC_ID_H264) { - enc_buf = bs->ExtParam; enc_info = (mfxExtAVCEncodedFrameInfo *)(*bs->ExtParam); ff_side_data_set_encoder_stats(&new_pkt, enc_info->QP * FF_QP2LAMBDA, NULL, 0, pict_type); - av_freep(&enc_info); - av_freep(&enc_buf); } #endif - av_freep(&bs); - av_freep(&sync); + av_freep(&tmp_struct); av_packet_move_ref(pkt, &new_pkt); @@ -1619,23 +1611,12 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q) while (q->async_fifo && av_fifo_size(q->async_fifo)) { AVPacket pkt; - mfxSyncPoint *sync; - mfxBitstream *bs; + QSVTmp *tmp_struct; av_fifo_generic_read(q->async_fifo, &pkt, sizeof(pkt), NULL); - av_fifo_generic_read(q->async_fifo, &sync, sizeof(sync), NULL); - av_fifo_generic_read(q->async_fifo, &bs, sizeof(bs), NULL); + av_fifo_generic_read(q->async_fifo, &tmp_struct, sizeof(tmp_struct), NULL); -#if QSV_VERSION_ATLEAST(1, 26) - if (avctx->codec_id == AV_CODEC_ID_H264) { - mfxExtBuffer **enc_buf = bs->ExtParam; - mfxExtAVCEncodedFrameInfo *enc_info = (mfxExtAVCEncodedFrameInfo *)(*bs->ExtParam); - av_freep(&enc_info); - av_freep(&enc_buf); - } -#endif - av_freep(&sync); - av_freep(&bs); + av_freep(&tmp_struct); av_packet_unref(&pkt); } av_fifo_free(q->async_fifo); From patchwork Sun Sep 26 06:40:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30584 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp3046647iob; Sat, 25 Sep 2021 23:41:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoGQ1oJ/dH499X+h5vrsaBYratRqU1YxJtqXgaA6fl86+kY8KhU3ab+a0o311jeQnvcY2b X-Received: by 2002:aa7:c459:: with SMTP id n25mr15701500edr.29.1632638475802; Sat, 25 Sep 2021 23:41:15 -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 u18si4510976edf.591.2021.09.25.23.41.15; Sat, 25 Sep 2021 23:41:15 -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=IPQdMjJC; 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 CF36368A97A; Sun, 26 Sep 2021 09:41:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-oln040092070041.outbound.protection.outlook.com [40.92.70.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AC0E668A929 for ; Sun, 26 Sep 2021 09:40:55 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mtD73LchSrJhwGi2afMUgiQ8xGbaXLEgUhaemLqikKT8wyT5PZJx9SJGLPX+q7X4opFXtWNefoAHSpOjaZgan0WazxYFCNTpa3wmx7FX45MyEqun93rpbWRtJNtpeJePyeJ8HouLYn0rhfvv3//6nZ/xUe5tob4Xax/OaLXqZGikov406xjmh5EUG2H18pzsCVtNqJPUwczNUHZiWxRX5op9rIXNjRaUNf/2byU2+tJXAXSS4RieL5EKJpMWSadi/CyGEuEgZE6zQNA0pn890z/sJ1uD0fAmrPNo+0WkW+QfNU4QtepYEUIByS++vHO1BI5+e9XwuL66a5Kj5yJ7AA== 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=KCDZex2c0gPFxPVRnWFQlDBr9kectynNYP5o0wUAOv8=; b=ZCCOLtzrT6sCMgza/1f9WZxqcTHL8/NW2cQ4Bpml4u69NVw8bm/ZM2LkCxDNDMlGW9EMTAgUTMpYVuxWBboZU7CYJxl5hVv1lyVH+B9n67ZCPhA/3uFnZxZZsp6See5Hx2BQEkrkeWJ/ZWnOlrWi+MQoE9FxXF3lux9Xj5inbzBzUYiOkbDNG0MYdPYWgHJlMN1fil2tRLx75ewMc+SJ2GxCKlX3FuIVq+v7DugYH5kk7ApRiMJIuSY1u2BAiVC30nnLqvlmRWBoxRCeZ02RC02FCEPAmY1oFY5zkkLsvaHE4cnkPXn8kMeg+5d1RDFm4X9c/0Da7fAWcFT0ksIiCA== 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=KCDZex2c0gPFxPVRnWFQlDBr9kectynNYP5o0wUAOv8=; b=IPQdMjJCHhsB30K6BF4AvGOA+RlCpD+CjF9T0m7gW/1md3njaJ2TAcHOpTSS0IiMEFIj/MGizXcll4dKUCAqfJBuaYRvNoqxahsu6RYPyNlm4C0HxRxhzo62d8Uh8WkuEA2IzNXqD2O/EguE02GnGcbhbf1B5Wmk/+94JdPox5vIT1/EFTJ8JnFuBkcKxMyNfwNnAIoYldUo3R6WXIGx4D+1+1tNUomfAJPko/hNMTHa67rfmMLRvx7yz2GXnlP1akqHxx3qxWBYodPEba7+T9tlm8m/rxEB+PzgxbPFwGAcRFjSxSyKEJYtZRM29atSUo5nyHn/cvNUbCROrnh43g== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3768.eurprd03.prod.outlook.com (2603:10a6:209:37::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.16; Sun, 26 Sep 2021 06:40:48 +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.4544.021; Sun, 26 Sep 2021 06:40:48 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Sep 2021 08:40:26 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [u//N/HIG342FX+32WZOCZXG+IkBmSPmp] X-ClientProxiedBy: AM4PR0302CA0010.eurprd03.prod.outlook.com (2603:10a6:205:2::23) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210926064027.344398-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM4PR0302CA0010.eurprd03.prod.outlook.com (2603:10a6:205:2::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.14 via Frontend Transport; Sun, 26 Sep 2021 06:40:48 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fd27ad7f-f4db-4436-6222-08d980b8937b X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiTijo6adWu98WfLBOWxl+RvHsOWP6mDguZ44Q0LEHUrj/j8lY7ld9+DsadQEaaUJpPxCWdelxXZ0USETuvVHxsnK03TIw4n49TmemFFmPbFSWqe4JkSUE95XA9HEmrGyAHAPCBkfN94NHed8efVSxGe367CUl30ewGK1c1klmWTs8qyU/sy4Oa3ZL0uSBDV6zdHVn17G5tyTMTwkp/mrwtvataHuLH5/ARIANA804Ku5LRAk3c8R4mLSljtlBZnvrpCfWnKiBj/+MR3GE4+7q10AFky/MYo+A+IiQKi8wv0wK+USDqs9OdlWDgOjhdIzhu0WMO0YbtB94+K6ytaJyurBp2eQT9kdHBdueIoZIBTjLAGTw5uM42JH3n9YRNrgRjOc7gDgwVGkd4SxV2yTD4K05ME5o4anJs4/2G/D80vxtChZebhOpomqlzd33y5qRdOBCN42yOVw/flwRhP7IrHL1gBwKqQOJsV8uU0vKoZ3GwISvoEDcYAszYvqaQorQ29hEKC3/w6V815HLL0iIedvCdx/wOARBkE5ASJSkw07UU7MSDz/bqSv8YMj9Hvm2tUctgjp/7cIwGCGv4vQjL+JQgmvuLrnsFjO89BhqlZ9pXAW2kJgtH/xNW5lNKfgRVdiDt+nJm/cvcRsgLlIoMdYd6gM+r5tpAvf/DBD3K4INVK/gb+AyBpWvS/tMhXGyL9cEGYbQvuYf3aMvN+XVEaubEe8E2qn9cmKNJv3ja8aR9J+7OZnkL/fYl1+5gcjVE= X-MS-TrafficTypeDiagnostic: AM6PR03MB3768: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 19pXTrsC5bXfj4HR38Q98OH2jr6Y7CCSXWEJme1ZWVIxJe2C2iZG2mhmsbRN0Xvtntz3tWcb4Zm0bNBFWYpR99YeEQPQ0Prevu1Dnk48nBqFg3nYe1ekr39U3NnVJ3062I5g5Efc0X9jt2HJRW8efuCEUUHUHGi0Ryx4W5v7H1dmnS9D3rCxT7vgRsFKedz8r3RKJl88rwit+pSJdWZ61fAI6aLgEeatnak0z/AFKPyAnKLI0H/50odV0BKa3x3WqAV9Yby+waQAA3lS6k6iqJnLfS8lQA51I6XwHNx/IYUyu1QfilioF6tRSq9hHWpbMSQ3UAPoodCTO/1ECO0x/0I0nnWTVcLR+Qet1DahP5dX2vUe1buAGbsVmi18R6y/aMfJyubm0n7dGyt5mjwfKJbPsHQ4P+WQ1wiv5CYZm1vIBgwL5B6nHzw5eLkJIAXr X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XLV+Ygyaw/FRqP/FkItOOg6/bMh86hfjmzX9awAcX4UGNnIE+J5/ZEmTjT2pWqJNSZOHqjjbuHXG03hVFIAmaoENEtUHX9L4jg9a2KdeAtH6M35J42yJ2bANJ8qr2cfGMuFKAZ2WCEvRAAmZaoTMBg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: fd27ad7f-f4db-4436-6222-08d980b8937b X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2021 06:40:48.8759 (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: AM6PR03MB3768 Subject: [FFmpeg-devel] [PATCH 5/6] avutil/hwcontext_qsv: Fix leak of AVBuffer and AVBufferRef 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: +h8WV7bZ0suR This av_buffer_create() does nothing but leak an AVBuffer and an AVBufferRef (except on allocation error). Fixes Coverity issue 1491393. Signed-off-by: Andreas Rheinhardt --- libavutil/hwcontext_qsv.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index c18747f7eb..4ed50a31a0 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -235,8 +235,6 @@ static AVBufferRef *qsv_pool_alloc(void *opaque, size_t size) if (s->nb_surfaces_used < hwctx->nb_surfaces) { s->nb_surfaces_used++; - av_buffer_create((uint8_t*)(s->handle_pairs_internal + s->nb_surfaces_used - 1), - sizeof(*s->handle_pairs_internal), qsv_pool_release_dummy, NULL, 0); return av_buffer_create((uint8_t*)(s->surfaces_internal + s->nb_surfaces_used - 1), sizeof(*hwctx->surfaces), qsv_pool_release_dummy, NULL, 0); } From patchwork Sun Sep 26 06:40:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30583 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp3046734iob; Sat, 25 Sep 2021 23:41:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/pJqcQVafFyVy3Fc5NBIruPxBTjlfplcqJBSk5Hhl4O0K8d6ZsgJu5jPAbsbqOJyC/OKr X-Received: by 2002:aa7:c744:: with SMTP id c4mr16024209eds.0.1632638486696; Sat, 25 Sep 2021 23:41:26 -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 q23si16653841ejr.192.2021.09.25.23.41.26; Sat, 25 Sep 2021 23:41:26 -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=FKUABg6Q; 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 BAFDD68A98B; Sun, 26 Sep 2021 09:41:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-oln040092070041.outbound.protection.outlook.com [40.92.70.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CEE2A68A929 for ; Sun, 26 Sep 2021 09:41:00 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XtrZbvRWmnlz6z50pRWl7UxyRV+Cd5QawmhWDv7blqoyVnlkheAEENtofGPSpmlvOG3rjHrc0hcWTlZ7+34FEzC5Ijxu9HZDV8URhJIEWOPZt/lutJz8/HpVHT71Dl1780fIt4aluvHbJ16j249BOeVyrwtd0sT9vWpdgOR9GG4hAZ6BltyEMVd76IrvE0P+ZI5v3Q7e+7xDHvPY3QciwRmkcwH03/oOl7TuVpclwCjoxn2Blsan6S+1ZCNH5jfDbzqeLTWa/C4MUg6BItv+mUMop+/MzZVtvcxoa8PbL6Vset1bUnnK2k2uv3a0PQ0g7EU/KBGk2zQTmP5xeX80cg== 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=607cDlkRnI5cHsuwly0175FyVnEhxg6w+f/wKd5j/iQ=; b=DM3WAsqeWdD2tVI5IfM1OYXqepivOER30dwBx45nEjIzH826MLNZesUwF90NZ0HpPKzAe6x3ja2VFvY7Ca6Nibb6E4OhfVQ76XtXgOmCfuD3OXs13xssgeKkapwqUt33/B2f8b8BglSuQeBfmgSdzMWTz8EVdpcilna0UlXb6oG7DvITCXcj+KxOv1mkaEN9SZFjZUY3JfvWewHIFysJ2Gwez9hws2Dw++U/dp88enNsCj7gP9Mo5R+3WQJYEkMhVbj7FN7zdEClfIAmiut+1MXId6JPJv72hmODIghzawOJQRj99Y+axePuN6MlZ+nhU4QyA+LWIyMK3iNGw08vVg== 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=607cDlkRnI5cHsuwly0175FyVnEhxg6w+f/wKd5j/iQ=; b=FKUABg6QbXRiFTdMRnVOmOnrtujVgyVyND41/n0h3pK1wpia7wXgq8oHXliKqinJYYQh1rCk8tHnNx+aTjq5BaSTb/+/D4V0BUTEnhU76qeQd5oSzHbezDPze3CM7FE9fUDzASK9ePcN8SI98nXAjanUg3rqrrQWdVmRph9XnIv/hyVRDK5/0mqdPgCQkUS2NLsEMG7a9hgzzazKzgh+bEEZQS0NUqr/ZvcQ7KRiK3ufryg7smBFwByTlLXFcoMKA+6OQvF+4mx4FBYFXb5LCy9VYMXyPlwuyuWsfqQ8MYIijwqrGed8fAY2R216/S3VxBYt2vvbC1tU0KYbs0ptCA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3768.eurprd03.prod.outlook.com (2603:10a6:209:37::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.16; Sun, 26 Sep 2021 06:40:50 +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.4544.021; Sun, 26 Sep 2021 06:40:50 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Sep 2021 08:40:27 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [LZ1iMwRY4GcCQRSH/l6WxA1mXDI0tBT5] X-ClientProxiedBy: AM4PR0302CA0010.eurprd03.prod.outlook.com (2603:10a6:205:2::23) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210926064027.344398-5-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM4PR0302CA0010.eurprd03.prod.outlook.com (2603:10a6:205:2::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.14 via Frontend Transport; Sun, 26 Sep 2021 06:40:49 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e1d0d967-5b18-4f73-e133-08d980b89428 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNWLGUKWLgTOP1tKS/WOBc8zEqGvdbBeJzYmM0aac2EyOPjDoXfRNyidI39F/6NBFOcGjIUmx/wm/XPWsi8rPbbFMP4X7++U1TWw0hEMQ8KvDlQ7lgD6YzotkUfpu7enXvz1aDRm82KxILQFNgf0YX+CQB6MRgoSJ3/GlRc5lQSKOalZ2qTQsg799JJMg9Z7gk7aJWas0/fjEV3g4haJ7JkInWJHHOA7gzYrXSU1npYgQIjgvCsdPhHvQP4DE9Fpwz/8XpetTW6/l1jJ+v3rpCjeuLNt7dP7Ojp0tUFmg+fvqv0Wm2wJi/lhe41U9f16im6hzH8TL0uzoP+vF/JE6ac7+hvP1lcmjzAe9rDrSAeDUKKyawPNvgsJ7WNRxcLYX02fmvcoUDwCaqeIjzbEnRiQZsKUNZrMCGAOck+r/5+7DaCqNxAD+WG0KIEMPO7L4dC4IyaNnP+mMc4KKCmrKz/mhuvrfSY2rtt8/C3q9MxKmQObL8C4PM6TAiRVbPHYWqnsSMfV+UhemaFsB8u6spQO5jmQizXXsWkOvpSBIJfvJrHtFi4HpXHdJh0mcbrPno5MiljumH44+NxEdHHczNZp0XP0v9LZ+yips5RNa/ldj68BITYCSxhNWW87GZ+SllD8Ctc/5e2G/8cxlBhgYbAzNOv5KmmGfvFiek1Xp6EHaDGKDHnSPjpKrS/2ztXdzm9bTc0sS0MrKihh49i8MMnj1OpM3XM4vl0= X-MS-TrafficTypeDiagnostic: AM6PR03MB3768: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RLDykHsmbTw0c0th3IT/mqbwLi7JxvsbZSm1ii44Eq6iNOqj0t6rYT5s1VDdWCO5/XM14XdMX6rF4LoBQWP4tu8ACAKmx5veJWF0Do1Il+qLfB9wfLwL1XV1B3vdT+W1qKuyZCTw6tlCcqzV6Xtm7xXpVE72Z9qdEEVCfqcxIfqlhSJC7rGNhzi3cBWJ2UDFa41PWhZDkVgyEppyDDr22WJgLULlMjLWUyYWrI46dQRGx57JZS7JShGxBmCSKnMn+CGGZ6fnK2LNBS5fMYvp7bewZLTFTFgW0Bogto8VPfESNj4IiEysxWLYUTFaB95i5/EOr18FEzAer41ZiiZON5UAg/YtxfER+FuqsDeVxCUS4jaRLg8VgvxFW83ec18CFI1uT3HBjbN4tTcBeGmorH4nSuPxvW92QX8xbtwwaeXKFS7XTw8G4qKB2OQvaf/C X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: G1tSgjDUO6j21Ns2C+Awkw0gqxVYyCnmF6J8XbVPg505Y9vqupRSWXrx4zsPhm2HtYk1yzd65fTI7ZqoD2NFi182knYf6SLfv5RFH0Vr6It+Lan3bY/VzMdXdNPBHqCQl+fn7phL5aM6hnjanO0zTA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e1d0d967-5b18-4f73-e133-08d980b89428 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2021 06:40:49.9891 (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: AM6PR03MB3768 Subject: [FFmpeg-devel] [PATCH 6/6] avutil/hwcontext_qsv: Remove redundant check 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: GDcM0gUvzKrc It has already been checked immediately before that said AVDictionaryEntry exists; checking again is redundant. Furthermore, av_hwdevice_find_type_by_name() requires its argument to be non-NULL, so adding a codepath that automatically calls it with that parameter is nonsense. The same goes for the argument corresponding to %s. Fixes Coverity issue 1491394. Signed-off-by: Andreas Rheinhardt --- If one wanted to sanitize something here, one should check for "if (e && e->value)" instead. Or unconditionally error out if (e && !e->value). libavutil/hwcontext_qsv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index 4ed50a31a0..268be9f8a1 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -1463,10 +1463,10 @@ static int qsv_device_create(AVHWDeviceContext *ctx, const char *device, e = av_dict_get(opts, "child_device_type", NULL, 0); if (e) { - child_device_type = av_hwdevice_find_type_by_name(e ? e->value : NULL); + child_device_type = av_hwdevice_find_type_by_name(e->value); if (child_device_type == AV_HWDEVICE_TYPE_NONE) { av_log(ctx, AV_LOG_ERROR, "Unknown child device type " - "\"%s\".\n", e ? e->value : NULL); + "\"%s\".\n", e->value); return AVERROR(EINVAL); } } else if (CONFIG_VAAPI) {