From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id EB0054D277 for ; Mon, 30 Jun 2025 15:01:52 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 3426068E318; Mon, 30 Jun 2025 18:01:40 +0300 (EEST) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 64A6F68E2D6 for ; Mon, 30 Jun 2025 18:01:34 +0300 (EEST) Received: by mail-pg1-f195.google.com with SMTP id 41be03b00d2f7-b350704f506so1015317a12.0 for ; Mon, 30 Jun 2025 08:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751295692; x=1751900492; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wQMwWRtMgWg/LpnSOreEmBiSRpogO/j95ghBqAs3cNM=; b=XB1VODBx97Aki1Vw3iMnEkNRV51HVuksnWAA3YLVadVjyxCUGN8dQAQrUq+AHMrJKg 1USJK57/6HN3V7nk4ySiRV2keLIW25iTeIz2t5+eHe5t9FXwFqktszt+1E8NXqhHlxaY oIHD2H8EnPGBZgro/GKkuOxEpZ9cxBcfZXrLApDhpVIz053dcWLmYDn+kDD3qDCXD4// 1t/v8uj5OEQBo3S4dK8IAkSiGckxyxRBfanFJwIrlUTHr4CzO2rLbXPRVh38B8edMhih 6COYMit3Xoe12RcIUy4bTAIf//82d45K5U+Gl2OprEJ+/hUgqADSk1p5TN2OeVRBDnI2 auPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751295692; x=1751900492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wQMwWRtMgWg/LpnSOreEmBiSRpogO/j95ghBqAs3cNM=; b=tlx5X+uEiSbKFiync7Ivb9FdLRtsrXawdfA75Wos+cJISlk2lB3uzeZTMyj7dZ+7iU iwyxnd1l2YE+eCj859zpXluEBhhpnLNok9hDyRe/Bhyyix8OaZnBDfHWFvxWBteUtOfZ R10MWLKQTJA4lR21Lv9hEL6K67ktCBUQb930JXXX1DU/0oVcdOcUexCnoENaOr1WaYMY Q1s/uGpiQ97iJ7jxOT2GSxy1GEFhtNbZSDLZo9u1mskMLhpq+TghOxTHjp6APOt2f1gI j64wA8xG9yV3TPIrCOMT272Q4dfNhQ3wpgmQZ8GvLfa8ZsD0oB9hJ9F/UWSDiZDq26+v khMA== X-Gm-Message-State: AOJu0YyudUktLWb8PrgJdvzuFRs7FRuWd6iR/wbTyaInAX9MCu2eE5QW hZWorunPfvOrJdIYe6PIiualJpHwNbw4k9L9G9nF5U9oUqb6lzeRmeKnhvgZLZgx2o7fnA== X-Gm-Gg: ASbGncviJZhRo8Q65HrCpEH5qrzyHQm7gqLKbGJIR2ePjCtIArcsSpj8EM9dRt5n2zz JM2kX9kzgP52jBun6+U8gF4NpJav41UZ9jg7X4FUyWxa4l75X7colG9e+IxyLvbM9N+qi2rCsQE XcEqzvzzKji9r+Zo7ey9QMOcJ0iYIpvb4cgpmxC0W7+P4iiCxeZE9EW129xKwPAh+sTJ5rT+TlN 3dg1oASyaTnLUzJD4L8C6taWLhn99Cc5joOAqGkA0rlRy3T1vJ/gsD09Z8N66TkXtIk/O4hXdPR RA2wLHLTokrlFBS/X+0rKZ+AwQjXXGMX/em/hwp9rzvIFF04Oihj0397XligyfUcP9/D X-Google-Smtp-Source: AGHT+IEG3HBvJENwSh+iujNox3bNpGR6TY51FpyJ404LA1YJDsgyk4CC2ehBk7d77wV464/9vLpMkw== X-Received: by 2002:a05:6a20:12d0:b0:1f3:31fe:c1da with SMTP id adf61e73a8af0-220a0cf7360mr21507464637.11.1751295691993; Mon, 30 Jun 2025 08:01:31 -0700 (PDT) Received: from r760 ([188.253.126.215]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74af541bd0fsm8963434b3a.40.2025.06.30.08.01.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 08:01:31 -0700 (PDT) From: Lidong Yan X-Google-Original-From: Lidong Yan <502024330056@smail.nju.edu.cn> To: ffmpeg-devel@ffmpeg.org Date: Mon, 30 Jun 2025 23:01:12 +0800 Message-ID: <20250630150114.2152464-2-502024330056@smail.nju.edu.cn> X-Mailer: git-send-email 2.50.0.106.gf0135a9047.dirty In-Reply-To: <20250630150114.2152464-1-502024330056@smail.nju.edu.cn> References: <20250630150114.2152464-1-502024330056@smail.nju.edu.cn> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 1/3] avfilter/asrc_sinc: fix leak in config_input() 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: Lidong Yan <502024330056@smail.nju.edu.cn> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: In config_input(), fir_to_phase() allocates memory in h[longer], which would leak if av_calloc() to s->coeffs failed. lpf() allocates memory in h[0] and h[1], which would leak if fir_to_phase() failed. To fix this leak, add av_free(h[longer]) in as cleanup code, and replace return AVERROR* with goto cleanup to prevent from leaks. Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn> --- libavfilter/asrc_sinc.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libavfilter/asrc_sinc.c b/libavfilter/asrc_sinc.c index 6ff3303316..05cf53fed8 100644 --- a/libavfilter/asrc_sinc.c +++ b/libavfilter/asrc_sinc.c @@ -329,7 +329,7 @@ static int config_output(AVFilterLink *outlink) SincContext *s = ctx->priv; float Fn = s->sample_rate * .5f; float *h[2]; - int i, n, post_peak, longer; + int i, n, post_peak, longer, ret; outlink->sample_rate = s->sample_rate; s->pts = 0; @@ -360,9 +360,9 @@ static int config_output(AVFilterLink *outlink) } if (s->phase != 50.f) { - int ret = fir_to_phase(s, &h[longer], &n, &post_peak, s->phase); + ret = fir_to_phase(s, &h[longer], &n, &post_peak, s->phase); if (ret < 0) - return ret; + goto cleanup; } else { post_peak = n >> 1; } @@ -370,17 +370,21 @@ static int config_output(AVFilterLink *outlink) s->n = 1 << (av_log2(n) + 1); s->rdft_len = 1 << av_log2(n); s->coeffs = av_calloc(s->n, sizeof(*s->coeffs)); - if (!s->coeffs) - return AVERROR(ENOMEM); + if (!s->coeffs) { + ret = AVERROR(ENOMEM); + goto cleanup; + } for (i = 0; i < n; i++) s->coeffs[i] = h[longer][i]; - av_free(h[longer]); av_tx_uninit(&s->tx); av_tx_uninit(&s->itx); + ret = 0; - return 0; +cleanup: + av_free(h[longer]); + return ret; } static av_cold void uninit(AVFilterContext *ctx) -- 2.50.0.106.gf0135a9047.dirty _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".