From patchwork Sun Aug 1 21:13:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29173 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6c0f:0:0:0:0:0 with SMTP id a15csp1049087ioh; Sun, 1 Aug 2021 14:13:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwj11sr+QuvUH5MdDP6jts9Xbs4WhQkPL7oD+jrQulqW30IlA8GslrmhBbZBUzqtWoPXGee X-Received: by 2002:a50:ec0a:: with SMTP id g10mr15614593edr.125.1627852412303; Sun, 01 Aug 2021 14:13:32 -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 d28si7722990ede.521.2021.08.01.14.13.31; Sun, 01 Aug 2021 14:13:32 -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=L+GRhxMA; 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 6130168060F; Mon, 2 Aug 2021 00:13:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-oln040092072091.outbound.protection.outlook.com [40.92.72.91]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 087E168060F for ; Mon, 2 Aug 2021 00:13:20 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c8sqMrTjttZNdGg3+5HjXUJEtWdoRwPeFOWlCP3DzRbP00a2sJTUnsp6sq6XsnmY6eKvM8YMPz7fNL35N86NDBnVKa0jzyiVKceseTGQZ3WVcz1lGtfaEFdtaoZtb7G2p0EoAQInFT1ydnR7GfCZgDahCTX+jBEb2+T0Zvtq52H2xtw0iutCSO3BVXcy71RY/tX/kSKf0/IsXDx60ULBctynIKv44nwwjzO6t8C5xEiTVveHzHzN34hADHkpCVRvJ2o8a3PIwUI+yP19PUqWzafNO7By+7DB7Ch0krHHXZ6bkbAVXadBPAjzbY2Kc4OvYq3pk0IlmZpWf70i2j9cYA== 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=eLj1p+4JlVtEczuiYK9QdIuF+oy5Dk3s055rXzelNv0=; b=T/WitayLitXRYngV+Z0gdlnMrLvWeUXjjFBvoVt8cCQ/T0Dzeq2UQH6y09Hvf2DLOMt68sSVGfp39uzkUiunxQtW8LEjxtGKvIlBoDbgiWJe2DzHgmmSxrKdD8jNp8H7lVLs7/zxUdVb9Hi77CuX4Smue9tuTJjGvzEZL2Nvmp92kCYdMYCVZ6CB8IA5/aO784jfCH9niwTwpnMLSEQu+8e++0G0pAuZRiuwjGm1rInNDeg5xO0XHHo9VE6Tsc0OAULwFLjAlNUDyJdTAScIgsdrVtUYHQdMkmclYwoxoYrUcN0ynmVHz940g09HYemBL/0nfGd+psguflpDuglmbQ== 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=eLj1p+4JlVtEczuiYK9QdIuF+oy5Dk3s055rXzelNv0=; b=L+GRhxMAGAyZvELme2WLR30TWhfiHNYAWo0sIhAULq4Qm/pHzywlIHE7ByI7FYTDN7Xv6LedS9JFgaWTHU+BPOX9yuLuRKV5SM9VeGgv5S6dKJ+ADYVPVMLVuJPrzijRDo91CUuZlsHF9CUSDUtZv9W1EZ9yHU1+pqP+OQJ61oxP1FyQh4N2BUkJXXWel0oSseo0ghGL9ErQc3lC5ZJ0YKdai37yX4To6MXkQPmQQcll83buYtakQ9418BThJpEZNLGq9snOUJyzBsSixlBK9kOKq/WakGBPtgHsFARDxjql82MlC6ZurY9IzXIFhCUUzLDG3TeA2hVl7xWJr+8JWw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM5PR03MB2930.eurprd03.prod.outlook.com (2603:10a6:206:1a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.31; Sun, 1 Aug 2021 21:13:19 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::c9b2:14f8:d555:6f2d]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::c9b2:14f8:d555:6f2d%8]) with mapi id 15.20.4373.026; Sun, 1 Aug 2021 21:13:19 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 1 Aug 2021 23:13:05 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 X-TMN: [JXJA2O3BOGg4bhT52SRNF9uZXQIfnbbD] X-ClientProxiedBy: AM0PR01CA0171.eurprd01.prod.exchangelabs.com (2603:10a6:208:aa::40) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210801211310.1005418-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.94.230) by AM0PR01CA0171.eurprd01.prod.exchangelabs.com (2603:10a6:208:aa::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.18 via Frontend Transport; Sun, 1 Aug 2021 21:13:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2eefc982-9e56-402c-1be5-08d955312fa3 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiRC6LfFJetu3tzwViwha8R8OkzMGgOoIEx54qFbGH+7Snci26Ju4CVpS8Pu5ZwlKQmMvCqmg0/qpQdcm7Qdz4uyoXp3yW/9BX+qXdzvZ5jwkNcq984k69N4dl2AxcOqPyQTftQXLYIolUX2FWHfJJgCvtRnCs7DNmKhEyrM36rkK12vcBp8Y9vQDGZ9k3sJ1Ye1G6KPD/ACOzYJ8sfZshC9Wk1e7DmpLmOAwcYuF8cCWHXhLef4rm8w6D35acrzA7fiEb9RMphNXBfHdHXlonJxcyxHUG3OMx8P0zXSRbEixLCGv4enXTujokZhFM/410qPjYJsht23bf2RoPvM+mKcX22hzSQ8Jdioluyccmd1z+qgsUghGk6US0UOi2LfB0zkhS+pZGzJwk+OVLMvTWJZt2xkEkkEKC8xUD2mBkpK6Su4Ub+dxjJUcQtEgqqzbbZUAgoC81Go/HOgKdcPmXTm9VvterGVlS7tHPKS7iNTqzfaIKnmQoiJn1NW6izqYWAvBz9uqj46SWyDq1KFEYv68VNkkvqrWD1md1mCumx4WpcjPOwoRc41UDhGKVR6an/H/9UlbDyab1KN8Jb7/DlKUJBOvNs81SXMRydnNntSD4+lqI2uND9a3VI/7pQ+o5WTOxLr4PpLF6DmCGjkG0yNPvCQePPlmPjsaqAknmxxD9eF7/oVureOGHDicx8YWrJXfwwqsgsUzXsOLCiIZc136diORRF/yOLEWNx669canT7zG4gXQvUSzDE9A9e65Ss= X-MS-TrafficTypeDiagnostic: AM5PR03MB2930: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sUCgunQx9ztj03Dw5kg+Oe8WXsFedEYYDYPYKQS69zkgrAMxQttLrjamD1G/xhmCryEmNU3bHg8aGXXlZTM/eYuC8qxrvIQcS6wul2yXyyaRUxeVM6bc2HFgVveEs1eaglOIjZTbfkDGTYahhMPkpvh/zp+agc/heParSlBJQ4RSej8J0ECzzB9Ixl5vUXNW+XRB9JWg33aQ40VFX3UBIhvcRlTurpz6TDXM5A61Lm6P1CPi3otzzd2osErInncu3NKFHAKAu48MUOpmqICmFnBG6jDfExyP0Yl+fHTq/eilvYl2JyHyV9pxgsU6u9aDz19tbd7urzRmt/Xg+MsJXIO7emqmyQB7gg1iMYW79riujfz0P6BLih6EEnTxiYmTRXYHfWNKxL78JesP8BWi+AvyfmKWbhKqq51PqCa+aoDBUHVVDOvinUMedX++61Vi X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WsZhkmyopBCokWcT6zXDNXF64kJUAmm1izJ5MO3hjMCog3MvLHTkp5yVldl2sWblj1/EthS0wNPZUY3Y/fGiBcXCZdPj28ry/L2/PW6KElYsaFNCPG50soQhI1/l+640o+jGKG13um9rDYVYhSNAug== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2eefc982-9e56-402c-1be5-08d955312fa3 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2021 21:13:19.3818 (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: AM5PR03MB2930 Subject: [FFmpeg-devel] [PATCH 1/6] avfilter/af_aderivative: Don't use audiobuf for only 1 sample, fix leak 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: XmEk6wZWJBO2 Up until now, the aderivative and aintegrate filters allocated an audio buffer with exactly one sample per channel via ff_get_audio_buffer(); if said buffer could not be allocated, a frame would leak, as freeing it has been forgotten. This commit instead uses a plain array for the audio buffer; it is allocated when configuring the filter, removing the error condition where the frame can leak. This fixes Coverity ticket #1197065. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_aderivative.c | 40 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/libavfilter/af_aderivative.c b/libavfilter/af_aderivative.c index 6b3e4dd0e4..559223d5ee 100644 --- a/libavfilter/af_aderivative.c +++ b/libavfilter/af_aderivative.c @@ -22,8 +22,8 @@ typedef struct ADerivativeContext { const AVClass *class; - AVFrame *prev; - void (*filter)(void **dst, void **prv, const void **src, + void *prev; + void (*filter)(void **dst, void *prv, const void **src, int nb_samples, int channels); } ADerivativeContext; @@ -63,22 +63,24 @@ static int query_formats(AVFilterContext *ctx) } #define DERIVATIVE(name, type) \ -static void aderivative_## name ##p(void **d, void **p, const void **s, \ +static void aderivative_## name ##p(void **d, void *p0, const void **s, \ int nb_samples, int channels) \ { \ + type *const p = p0; \ int n, c; \ \ for (c = 0; c < channels; c++) { \ const type *src = s[c]; \ type *dst = d[c]; \ - type *prv = p[c]; \ + type prv = p[c]; \ \ for (n = 0; n < nb_samples; n++) { \ const type current = src[n]; \ \ - dst[n] = current - prv[0]; \ - prv[0] = current; \ + dst[n] = current - prv; \ + prv = current; \ } \ + p[c] = prv; \ } \ } @@ -88,22 +90,24 @@ DERIVATIVE(s16, int16_t) DERIVATIVE(s32, int32_t) #define INTEGRAL(name, type) \ -static void aintegral_## name ##p(void **d, void **p, const void **s, \ +static void aintegral_## name ##p(void **d, void *p0, const void **s, \ int nb_samples, int channels) \ { \ + type *const p = p0; \ int n, c; \ \ for (c = 0; c < channels; c++) { \ const type *src = s[c]; \ type *dst = d[c]; \ - type *prv = p[c]; \ + type prv = p[c]; \ \ for (n = 0; n < nb_samples; n++) { \ const type current = src[n]; \ \ - dst[n] = current + prv[0]; \ - prv[0] = dst[n]; \ + dst[n] = current + prv; \ + prv = dst[n]; \ } \ + p[c] = prv; \ } \ } @@ -122,6 +126,10 @@ static int config_input(AVFilterLink *inlink) case AV_SAMPLE_FMT_S16P: s->filter = aderivative_s16p; break; } + s->prev = av_calloc(inlink->channels, av_get_bytes_per_sample(inlink->format)); + if (!s->prev) + return AVERROR(ENOMEM); + if (strcmp(ctx->filter->name, "aintegral")) return 0; @@ -146,15 +154,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) } av_frame_copy_props(out, in); - if (!s->prev) { - s->prev = ff_get_audio_buffer(inlink, 1); - if (!s->prev) { - av_frame_free(&in); - return AVERROR(ENOMEM); - } - } - - s->filter((void **)out->extended_data, (void **)s->prev->extended_data, (const void **)in->extended_data, + s->filter((void **)out->extended_data, s->prev, (const void **)in->extended_data, in->nb_samples, in->channels); av_frame_free(&in); @@ -165,7 +165,7 @@ static av_cold void uninit(AVFilterContext *ctx) { ADerivativeContext *s = ctx->priv; - av_frame_free(&s->prev); + av_freep(&s->prev); } static const AVFilterPad aderivative_inputs[] = {