From patchwork Wed Dec 28 02:43:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Turner X-Patchwork-Id: 1954 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp1754629vsb; Tue, 27 Dec 2016 18:43:44 -0800 (PST) X-Received: by 10.28.88.18 with SMTP id m18mr28879311wmb.26.1482893024434; Tue, 27 Dec 2016 18:43:44 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hc8si52152655wjc.214.2016.12.27.18.43.44; Tue, 27 Dec 2016 18:43:44 -0800 (PST) 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=@googlemail.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=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E0B43689D8E; Wed, 28 Dec 2016 04:43:28 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f65.google.com (mail-pg0-f65.google.com [74.125.83.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 32006689975 for ; Wed, 28 Dec 2016 04:43:22 +0200 (EET) Received: by mail-pg0-f65.google.com with SMTP id g1so14152782pgn.0 for ; Tue, 27 Dec 2016 18:43:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=eUbtDeOxHg9usRqsUoYmdJc6aQZ2iEx2caxDVanW2t4=; b=tl20YkP0YYG/y5O3B5iQkL26D7OGWptgCrsufzQkzUBBq2ltSWRm6CSLLWRaycljBg UZ7+k1YHxxZD50+Ptovc0ebymbrUWpoqVRZ8bqVSdVdqVNImWclzC0TAI1kIMV+q16F2 YM9jJnD5gtyudi0WdJ+Zxygzg1/WaENvhMEnUqZW2xMqauRHltPiW2ww1CM1zM4uySfg ALmEGpTUYXF1Hu2rvus0xfm+eY97ScIt559u9bqAdtgcw656FUiPPNNRoGySa+DAuKY1 Xq8q78EkF6+bP1aZ2kxakfJ8Eib85OB/6/WDJyiZUlEIA4Lxso0ZD13OPBfuESg0A9LN nBhw== 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:in-reply-to :references; bh=eUbtDeOxHg9usRqsUoYmdJc6aQZ2iEx2caxDVanW2t4=; b=QZY6LzMoRCK+ZxbBskATCghf3Nlic+yFeYghWoTC1HfLfFF27m9sekd0pWjwT3qLe/ EvbwAOMo7nqe8+f1ale3kP5DE6QJaxvqsrbwaDn+RaLxoitiKOrvBH+qIUImS8h1MvIZ yMMaKXC1xU4X2if291JrbqbJthF5WUzqAPC/3mM6ZDKhdT9l+rR0f4YdBKT05rZJQPd+ bdq9w0YNG8mNG4d5bJA0+Kk200pZtBQUpDo9/RAROjIe8tt0VNJpObt4cIEIsTHQkoYO UEp8JStOPsIkVNx5zYzSx/poG6s1equDfvfyPeS3KHNx2Y4MIiVVAikGSilbwppr/pok oWhw== X-Gm-Message-State: AIkVDXIPBHxUT/p5BaAxkPt54/u8LSD0eomI2LQk9961NXCmtdUyRXy0p6UWHD9v/oSJng== X-Received: by 10.98.100.66 with SMTP id y63mr32640337pfb.49.1482893003522; Tue, 27 Dec 2016 18:43:23 -0800 (PST) Received: from Zany.fios-router.home ([47.147.141.23]) by smtp.gmail.com with ESMTPSA id t3sm49850560pfb.60.2016.12.27.18.43.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 27 Dec 2016 18:43:23 -0800 (PST) From: Thomas Turner To: ffmpeg-devel@ffmpeg.org Date: Tue, 27 Dec 2016 18:43:19 -0800 Message-Id: <1482893000-29962-2-git-send-email-thomastdt@googlemail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1482893000-29962-1-git-send-email-thomastdt@googlemail.com> References: <1482893000-29962-1-git-send-email-thomastdt@googlemail.com> Subject: [FFmpeg-devel] [PATCH 2/3] avutil/tests/audio_fifo.c: Memory leak and tab space fixes 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" Prevents memory leak when read_samples_from_audio_fifo() is called more than once by deallocating before reallocating more memory. Fixes space indentation for contents in ERROR(). Signed-off-by: Thomas Turner --- libavutil/tests/audio_fifo.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libavutil/tests/audio_fifo.c b/libavutil/tests/audio_fifo.c index 9dc6054..2cef6f0 100644 --- a/libavutil/tests/audio_fifo.c +++ b/libavutil/tests/audio_fifo.c @@ -45,10 +45,19 @@ static const TestStruct test_struct[] = { {.format = AV_SAMPLE_FMT_FLTP , .nb_ch = 2, .data_planes = {data_FLT, data_FLT+6, }, .nb_samples_pch = 6 } }; +static void free_data_planes(AVAudioFifo *afifo, void **output_data) +{ + int i; + for (i = 0; i < afifo->nb_buffers; ++i){ + av_freep(&output_data[i]); + } + av_freep(&output_data); +} + static void ERROR(const char *str) { - fprintf(stderr, "%s\n", str); - exit(1); + fprintf(stderr, "%s\n", str); + exit(1); } static void print_audio_bytes(const TestStruct *test_sample, void **data_planes, int nb_samples) @@ -80,6 +89,8 @@ static int read_samples_from_audio_fifo(AVAudioFifo* afifo, void ***output, int void **data_planes = av_malloc_array(afifo->nb_buffers, sizeof(void*)); if (!data_planes) ERROR("failed to allocate memory!"); + if (*output) + free_data_planes(afifo, *output); *output = data_planes; for (i = 0; i < afifo->nb_buffers; ++i){ @@ -173,10 +184,7 @@ static void test_function(const TestStruct test_sample) } /* deallocate */ - for (i = 0; i < afifo->nb_buffers; ++i){ - av_freep(&output_data[i]); - } - av_freep(&output_data); + free_data_planes(afifo, output_data); av_audio_fifo_free(afifo); }