From patchwork Tue Mar 21 01:33:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 3040 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.50.79 with SMTP id y76csp1693925vsy; Mon, 20 Mar 2017 21:34:35 -0700 (PDT) X-Received: by 10.28.230.83 with SMTP id d80mr745014wmh.18.1490070875008; Mon, 20 Mar 2017 21:34:35 -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 g10si14712088wme.166.2017.03.20.21.34.34; Mon, 20 Mar 2017 21:34:34 -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=@gmail.com; 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=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0B3116891EB; Tue, 21 Mar 2017 06:34:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f194.google.com (mail-qk0-f194.google.com [209.85.220.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C433C68835B for ; Tue, 21 Mar 2017 06:34:06 +0200 (EET) Received: by mail-qk0-f194.google.com with SMTP id n141so20777182qke.3 for ; Mon, 20 Mar 2017 21:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=gGZkfVirOevXonGeibyhaeT5ICokxdCsyMWhSGe5/7o=; b=rGInpcaaVW0jOMi6vZJfv0wHSUgPg2Eb40NUcKCEL2cQSuWr5BHB8hHgpUKEk5hV/V R/ClyYPhlWdBh4sCbP7gOEaTilVs2fQMF6tU9XjDq9VrTaYmupm+K/Oh27x+jPyqABLV vShtjpBRJ77U1A1h7h2E2Ok1Ecyo/gxQTVzSOMMAaxagaFd9D+hqR0GBOs+OgLxAJKNd 2oOq2Nkb8lwatzvsUMBxvQZvoEp/QOiwIr97Ow/d1kGtuUHTJ/k0nF/cYNfz39GEj0OQ XVAwl7mHDISQP0063olvwA++F060EGQnZEKlq3rci3M9f6mXyn9YtUolgQGarjlg3Oh+ PeeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=gGZkfVirOevXonGeibyhaeT5ICokxdCsyMWhSGe5/7o=; b=Z4nwnPQDtI89G4Hi3R9YJzchkwBT6dirbAY3KBGs/U+bdVx7c7JCawZp2b5SaGh04O SMy4tpUCB3B+HNmkbbpwmB1Fe8PcPk58xjXipiLPM5ePjLmnOw4LXKHsgpdbOGro+ky1 na4uvDTxKVIbwwO2s5P31lSgaJ10T5i5RqmDymDO8dm+1QqhjH54c56JVRKihW+ymHs4 Xck5ezA8v5d7U6H8tB3pt5TCT2Gz+UWXrO5E0Velb/6L2JSEBTM8xFZ+S+OPw0LLbV62 9jc8m86lawU4v6De2+qOTEZfzSd3itvzE/QHjFxCylPhtqi3d/cpWjP7i9OFtZZL4rzw +s8g== X-Gm-Message-State: AFeK/H3vpOrs70D9hsBPnIh1Oa2psBNdL7bSzjelatxIoPOBYNMXNICgGizt0+uKosu/UA== X-Received: by 10.55.147.131 with SMTP id v125mr26876874qkd.39.1490070864063; Mon, 20 Mar 2017 21:34:24 -0700 (PDT) Received: from localhost.localdomain ([181.231.62.139]) by smtp.gmail.com with ESMTPSA id u5sm13979578qkd.46.2017.03.20.21.34.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Mar 2017 21:34:23 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 20 Mar 2017 22:33:53 -0300 Message-Id: <20170321013353.14128-1-jamrial@gmail.com> X-Mailer: git-send-email 2.12.0 Subject: [FFmpeg-devel] [PATCH] swr/resample: free existing ResampleContext on reinit 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes memleak (See opus-testvector12 fate test). Signed-off-by: James Almer --- libswresample/resample.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libswresample/resample.c b/libswresample/resample.c index 144b232462..ad6410142b 100644 --- a/libswresample/resample.c +++ b/libswresample/resample.c @@ -276,6 +276,13 @@ fail: return ret; } +static void resample_free(ResampleContext **c){ + if(!*c) + return; + av_freep(&(*c)->filter_bank); + av_freep(c); +} + static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff0, enum AVSampleFormat format, enum SwrFilterType filter_type, double kaiser_beta, double precision, int cheby, int exact_rational) @@ -302,6 +309,7 @@ static ResampleContext *resample_init(ResampleContext *c, int out_rate, int in_r if (!c || c->phase_count != phase_count || c->linear!=linear || c->factor != factor || c->filter_length != filter_length || c->format != format || c->filter_type != filter_type || c->kaiser_beta != kaiser_beta) { + resample_free(&c); c = av_mallocz(sizeof(*c)); if (!c) return NULL; @@ -371,13 +379,6 @@ error: return NULL; } -static void resample_free(ResampleContext **c){ - if(!*c) - return; - av_freep(&(*c)->filter_bank); - av_freep(c); -} - static int rebuild_filter_bank_with_compensation(ResampleContext *c) { uint8_t *new_filter_bank;