From patchwork Mon Jan 27 06:00:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 17580 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 08B1F4498CF for ; Mon, 27 Jan 2020 08:01:03 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D8FC2687FF2; Mon, 27 Jan 2020 08:01:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9D785687F87 for ; Mon, 27 Jan 2020 08:00:56 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id q6so9544857wro.9 for ; Sun, 26 Jan 2020 22:00:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/Ltc6Id49/K8OOG7pZ2sEvb3244d3n6uqJ0GYGQdVwU=; b=DqCIb7hzbklh6nr+305BXJwcvNC0Tr/oUU8x45mXavCJnyZutkiSU72nfRKlzJz/Wb Sx0Y4deqxiGmJpDP4p6Eugk3eWApPOZ6byJU4AwDxGdZr0nLZ7Q0Ze507SxmQk1IyboM V2ujVyhDfmaR/fkr6N1m5Et28+N4EDhiRLFEUFg8WdcLPV0Knjfv31+lHlASH6w7li1w gTU32oH/LAWC3nT4BSAPqsgF3I2tpwPxEUop1JfK3LAll4jSnoZbhdRVdTWlEDs1pkil XFzWg218u5O+U7CHYksXG4epQyhezdy4Fs5QTUlVHgDsixpmMbwy9VsA+ianwHaRGX2N dEIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/Ltc6Id49/K8OOG7pZ2sEvb3244d3n6uqJ0GYGQdVwU=; b=GY7no/6UTrOiDMPn44BuZHBM3942pVoDgh92BIM9MY9o+Jy60uFydKl/tOTM5w0c5T x/Ur1+oZrC3M7mC5IUWRwcBCbAGeGkXa2HonAav3YbrB5VQh5BWTxI4iYHawpeqopEyP dhFJ6dBPblsXM81m4LwESvdN2IxJg5s9XkuG3hJ60hwr/qMWeJNJzFz9TmWE8+tR5ju6 9VFezHZhslTEY6ixVlwlf7eh3Xp69XmpGJudPW56xKgOFqnvQZq+UTf1iQna4gRVu4AW IH75fzY2hhqtWzCds3wFYf+RyWFPCAqIdIv2zz7InKsFSsAD6/vU+VFMg7P4nd2ViInS Ifqw== X-Gm-Message-State: APjAAAULM3/0AFk1EDrc95RuZnS6c+h3AZSrSMoLLaEto0PuAz4q0ahc ZMOaH+0+e9gL/FjdlpEHA9dLdrG3 X-Google-Smtp-Source: APXvYqykZxYp/uDx9OxihZY2OhNj41N3fvG8rzIiiUsB2P3eyc08+xQfEY4gabIaIN/k/nGA0pg2fA== X-Received: by 2002:a5d:5267:: with SMTP id l7mr19051929wrc.84.1580104855898; Sun, 26 Jan 2020 22:00:55 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08bbf.dynamic.kabel-deutschland.de. [188.192.139.191]) by smtp.gmail.com with ESMTPSA id b16sm19317733wrj.23.2020.01.26.22.00.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2020 22:00:55 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Jan 2020 07:00:48 +0100 Message-Id: <20200127060048.5229-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avfilter/asrc_sinc: Don't allocate arrays separately 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Besides the obvious advantages this also fixes a potential memleak: If only one of the arrays had been successfully allocated, the other would leak. This also fixes Coverity issues #1440386 and #1440387. Signed-off-by: Andreas Rheinhardt --- During testing with -f lavfi -i sinc all I got is one output frame. Is this intended or did I do something wrong? libavfilter/asrc_sinc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libavfilter/asrc_sinc.c b/libavfilter/asrc_sinc.c index 90f043d680..24aeab6e7b 100644 --- a/libavfilter/asrc_sinc.c +++ b/libavfilter/asrc_sinc.c @@ -227,10 +227,11 @@ static int fir_to_phase(SincContext *s, float **h, int *len, int *post_len, floa for (i = *len, work_len = 2 * 2 * 8; i > 1; work_len <<= 1, i >>= 1); - work = av_calloc(work_len + 2, sizeof(*work)); /* +2: (UN)PACK */ - pi_wraps = av_calloc(((work_len + 2) / 2), sizeof(*pi_wraps)); - if (!work || !pi_wraps) + /* The first part is for work (+2 for (UN)PACK), the latter for pi_wraps. */ + work = av_calloc((work_len + 2) + (work_len / 2 + 1), sizeof(float)); + if (!work) return AVERROR(ENOMEM); + pi_wraps = &work[work_len + 2]; memcpy(work, *h, *len * sizeof(*work)); @@ -240,7 +241,6 @@ static int fir_to_phase(SincContext *s, float **h, int *len, int *post_len, floa s->rdft = av_rdft_init(av_log2(work_len), DFT_R2C); s->irdft = av_rdft_init(av_log2(work_len), IDFT_C2R); if (!s->rdft || !s->irdft) { - av_free(pi_wraps); av_free(work); return AVERROR(ENOMEM); } @@ -323,7 +323,6 @@ static int fir_to_phase(SincContext *s, float **h, int *len, int *post_len, floa *len = end - begin; *h = av_realloc_f(*h, *len, sizeof(**h)); if (!*h) { - av_free(pi_wraps); av_free(work); return AVERROR(ENOMEM); } @@ -338,7 +337,6 @@ static int fir_to_phase(SincContext *s, float **h, int *len, int *post_len, floa work_len, pi_wraps[work_len >> 1] / M_PI, peak, peak_imp_sum, imp_peak, work[imp_peak], *len, *post_len, 100.f - 100.f * *post_len / (*len - 1)); - av_free(pi_wraps); av_free(work); return 0;