From patchwork Sun Oct 6 05:01:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15520 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 82F3444016F for ; Sun, 6 Oct 2019 08:10:35 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6D7D9687FE0; Sun, 6 Oct 2019 08:10:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 65227680CFF for ; Sun, 6 Oct 2019 08:10:27 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id r3so11450980wrj.6 for ; Sat, 05 Oct 2019 22:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YFLd6G7ElcJJplN64RmBzubjMtoSS8Y+dq4Wg8Sgfwg=; b=KD0x0W0R4m2c9/vjAio5P8M7T0WL/3nsn8IT5s2++xTw77Ce4ww9NsLee4y9kWk1jD ICZuW5ngu2pEch7Zi1JSt3G/FCv7ZG1phnBX1kwkhplwKKMJglPmPu7OJoHrFBWpLY0c uC6+axG5yiugNfQXKffkgLj8A0S1YCNGNc3xMFZzk/R9KJuAXo4bZu+xb/u6bgPMmhXB C0W4/1gryub9QiQPUiJqCwPYlUeIlCJjdiAG93VpMwg4i+FmRLBljYQyNToPVIzXxOaO syRcPXgePrfd2I0r49f5UqrhYOOL3ZnkxbWApgXz8XfKyj3CNl7Jh2VEl7usOhXlbI4a 4+Ew== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=YFLd6G7ElcJJplN64RmBzubjMtoSS8Y+dq4Wg8Sgfwg=; b=pP5W2SvMp+IOEbsTe6wqJHXUh7ucg8/Lt18P/rdv6tyZU3u/6qydYZ1l4nW8gQiMyH CGGWg8cCzbOzYUcCcUiEQqR54ltEtWGyPbP765YcPnKaAeHn2fScBIZ8ApoNELZ3mORw bhW3kVPN2IOX9r2GDr0w1fBTmrCraBxocvMA21CqtKgtLgNT8dSZ4rF+qypZUaxOX1lY CbcbmVHwmYwfcUchd4dV3KgweBIiTz86lSwP//eWjhUW7JhdJzT+cLgwzSNJV2v4v5fe SjZYOkALsgGZtRQrrp0aiDKcvOMh4/b3qteQjmYT9TPXylb11RhWSYkrWWYTRj8QuQmt 18Vg== X-Gm-Message-State: APjAAAXygMT5sfeickVU+dGaqQxIhdCcaUoVKkJkYdDSqciDg3nFruug 2CI3dtUsVsrETaZt7OgcFaxHYClQiAs= X-Google-Smtp-Source: APXvYqwcAZVsy4eM5qXTVaKoYzi29fJL8tuMybYuBvYy2kYh3e3TYreE20KXACl/ZnX5xOzKV24mlA== X-Received: by 2002:a05:6000:14c:: with SMTP id r12mr17337254wrx.303.1570338626745; Sat, 05 Oct 2019 22:10:26 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08937.dynamic.kabel-deutschland.de. [188.192.137.55]) by smtp.gmail.com with ESMTPSA id s10sm18543014wmf.48.2019.10.05.22.10.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2019 22:10:26 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 6 Oct 2019 07:01:14 +0200 Message-Id: <20191006050120.26807-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191006050120.26807-1-andreas.rheinhardt@gmail.com> References: <20191006050120.26807-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/10] avcodec/flac_parser: Don't allocate array 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" The FLACHeaderMarker structure contained a pointer to an array of int; said array was always allocated and freed at the same time as its referencing FLACHeaderMarker; the pointer was never modified to point to a different array and each FLACHeaderMarker had its own unique array. Furthermore, all these arrays had a constant size. Therefore include this array in the FLACHeaderMarker struct. Signed-off-by: Andreas Rheinhardt --- sizeof(FLACHeaderMarker) didn't increase for me (on x64) with this patch, because there are now 2x4 bytes of padding less. libavcodec/flac_parser.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/libavcodec/flac_parser.c b/libavcodec/flac_parser.c index 5d0705ce63..2658d3c4dc 100644 --- a/libavcodec/flac_parser.c +++ b/libavcodec/flac_parser.c @@ -58,8 +58,9 @@ typedef struct FLACHeaderMarker { int offset; /**< byte offset from start of FLACParseContext->buffer */ - int *link_penalty; /**< pointer to array of local scores between this header - and the one at a distance equal array position */ + int link_penalty[FLAC_MAX_SEQUENTIAL_HEADERS]; /**< array of local scores + between this header and the one at a distance equal + array position */ int max_score; /**< maximum score found after checking each child that has a valid CRC */ FLACFrameInfo fi; /**< decoded frame header info */ @@ -190,14 +191,6 @@ static int find_headers_search_validate(FLACParseContext *fpc, int offset) } (*end_handle)->fi = fi; (*end_handle)->offset = offset; - (*end_handle)->link_penalty = av_malloc(sizeof(int) * - FLAC_MAX_SEQUENTIAL_HEADERS); - if (!(*end_handle)->link_penalty) { - av_freep(end_handle); - av_log(fpc->avctx, AV_LOG_ERROR, - "couldn't allocate link_penalty\n"); - return AVERROR(ENOMEM); - } for (i = 0; i < FLAC_MAX_SEQUENTIAL_HEADERS; i++) (*end_handle)->link_penalty[i] = FLAC_HEADER_NOT_PENALIZED_YET; @@ -559,7 +552,6 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx, curr->max_score, curr->offset, curr->next->offset); } temp = curr->next; - av_freep(&curr->link_penalty); av_free(curr); fpc->nb_headers_buffered--; } @@ -584,12 +576,10 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx, for (curr = fpc->headers; curr != fpc->best_header; curr = temp) { temp = curr->next; - av_freep(&curr->link_penalty); av_free(curr); fpc->nb_headers_buffered--; } fpc->headers = fpc->best_header->next; - av_freep(&fpc->best_header->link_penalty); av_freep(&fpc->best_header); fpc->nb_headers_buffered--; } @@ -745,7 +735,6 @@ static void flac_parse_close(AVCodecParserContext *c) while (curr) { temp = curr->next; - av_freep(&curr->link_penalty); av_free(curr); curr = temp; }