From patchwork Sun Oct 6 05:01:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15518 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 80C9A449E9C for ; Sun, 6 Oct 2019 08:10:32 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 68B1B687F86; Sun, 6 Oct 2019 08:10:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AFD3968099D for ; Sun, 6 Oct 2019 08:10:25 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id b9so11465827wrs.0 for ; Sat, 05 Oct 2019 22:10:25 -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=/7c3JE4FKQLllLqOB5NGB2VSiusLu729iXYVCFis0wM=; b=MiAouyZo+Q+b9YULUQK+bGwZVOE/xp6gJ5zlq+I8+qw0ub/ZQXOPiMuXkZnGG3iEuH 70z6CJrVW9HIDtdLeQ5eb0P5HSAQ++vPrQ7LlO7OaE2d9OXshbJ7prdQK87VNP6PJKmS IJbhrfr9+yeWmMC7lf8av0yfdH2gFMkON3nxb0iiQM5bLZSXIAzjVWtAVowZCl546412 RhG1lUnRQmr3gHG6j4r1h+uLQrQzZfGja1s7zaofdU1Ukix7tiEnyc+qv/uZ0E2VrTmV aJEyBvnj0Q35//FZPkDLugV5a5WoPxvBFpufK5qWA1OvuDlxm0zxx4PR7Ev2Q16ZiPed A7aA== 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=/7c3JE4FKQLllLqOB5NGB2VSiusLu729iXYVCFis0wM=; b=W2qntCsAsTMvuYKY+7+FX/Q5ili/K+xiyFYnwd9TR2S65BV28mYXpJhtI08OExZvbS h9yaANvzyOeXmbRCGnQNejx85MWaBBokGY67JtY+CfaK6NBGtvXJN4lTt5FXrGgxLqYL DVd7SJ3nQjUWX4Ls8uY92UdaLb2P/OL5e9/7yHZuqVS4onlHM12ZtV8C12w9ctCaKIIk JanbWvUZozW1Nd0vivmrvJgbfsHqqNVM3722pl6BYkah9ZWnvkBT9W8Xvk+/NrKoSQeu 18yuWEJWDiVhIUtiLznsuryiJJPUV0LeRaUfa4Yb+vHb24lys4W1xADc3ntoAMuw0fVT LmRw== X-Gm-Message-State: APjAAAXR/1/H9Cvd3s4aiyNQ7DCPbyKnY43bY5b93zhHxOw/Use6tsr+ KrgTke+pyCK2yt/4elhaMpD9Q/x2LW0= X-Google-Smtp-Source: APXvYqw+FJGNFG2nhtxc02BGKGfMB8/rAL4ShQfvtekjjy7aMjU/TbHgvx7Gwli73kqEUW9Ti1UVZA== X-Received: by 2002:a5d:45c7:: with SMTP id b7mr8457352wrs.356.1570338625075; Sat, 05 Oct 2019 22:10:25 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2019 22:10:24 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 6 Oct 2019 07:01:12 +0200 Message-Id: <20191006050120.26807-2-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 02/10] avformat/flac_picture: Avoid allocation of AVIOContext 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" Put an AVIOContext whose lifetime doesn't extend beyond the function where it is allocated on the stack instead of allocating and freeing it. Signed-off-by: Andreas Rheinhardt --- libavformat/flac_picture.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c index 8317ab2fa6..f0871d9c79 100644 --- a/libavformat/flac_picture.c +++ b/libavformat/flac_picture.c @@ -26,6 +26,7 @@ #include "flac_picture.h" #include "id3v2.h" #include "internal.h" +#include "avio_internal.h" int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size) { @@ -33,15 +34,13 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size) enum AVCodecID id = AV_CODEC_ID_NONE; AVBufferRef *data = NULL; uint8_t mimetype[64], *desc = NULL; - AVIOContext *pb = NULL; + AVIOContext pb0, *pb = &pb0; AVStream *st; int width, height, ret = 0; int len; unsigned int type; - pb = avio_alloc_context(buf, buf_size, 0, NULL, NULL, NULL, NULL); - if (!pb) - return AVERROR(ENOMEM); + ffio_init_context(pb, buf, buf_size, 0, NULL, NULL, NULL, NULL); /* read the picture type */ type = avio_rb32(pb); @@ -145,14 +144,11 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size) if (desc) av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL); - avio_context_free(&pb); - return 0; fail: av_buffer_unref(&data); av_freep(&desc); - avio_context_free(&pb); return ret; }