From patchwork Sun Oct 6 05:01:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15517 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 BD40F449D7A for ; Sun, 6 Oct 2019 08:09:44 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9DBCB680951; Sun, 6 Oct 2019 08:09:44 +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 373F66808E5 for ; Sun, 6 Oct 2019 08:09:38 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id n14so11391592wrw.9 for ; Sat, 05 Oct 2019 22:09:38 -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:mime-version :content-transfer-encoding; bh=QSYW1n370xOcGkQspLwHU9QcSXcXg1kENNr9Ws6gQJE=; b=AS4Ur5erdOyMcI0/NAZPlc35bF+3AYLF+9bp7uF79ymOIBEcIwWrWLLZLAVTu5ifD6 m8s0WrN2YCLwcChb10hCTsysCbTROuNAvY3/vI9JsMjeFmZPjiomz7aZZDQDdyYQ1Gu+ gSzxo9ORf2QDquNls1Hxgq9a3CovU75JvtITCP5nUqyDlurMZVm6+yeHA7JTpt6YH6Zg 8SRF9qO7/r+1adgcdCBxQTKVSiZCZpb9BFYNlEXSjs93i0BIskogtcLf0Si/WhqvW4YE ot5nBpkb86UpZD5SBtsoGa8Q4oWBQknI6flhKqoVW7TRxpdDIxEJpSzh8djnWTYpYP9d Iumg== 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:mime-version :content-transfer-encoding; bh=QSYW1n370xOcGkQspLwHU9QcSXcXg1kENNr9Ws6gQJE=; b=Pvrm6IUYnVBeJFN4wxs13DIBjcKT70UjxMwzusY+M9lfBIf0c8i7kjZOoX0BACJQUO tyHRbESRzdJqLNRN3wTuYSZDMtG0FepVeTCfqBryL8V/Gy14wMHGxP88Dt7cSrOaPy2G mGXiYPVlvh6CByqjlsCgdjIEIEzqZ8ZaYibcA+QW/wHzBI6xt2QLlndET7WxxGb2hqqS yuMNjvE6cUjLDUd4C4pFsXJ9vCs1m6dnk/xlncDX02ncLCc6hRNLI4gP+cER0O2EJNCv p+Z29YdV19yptvl2Rtoc5too42MD/yxA3//0o2atFYRBZTMVjUMFSZ0p8BDVbRTZ+/ep L+ew== X-Gm-Message-State: APjAAAUJG824C1ftZV34Hg9cRs/JvMKzP8m8v5ISr5aNbW0kqeS09IL0 KrL4Sth9UkITF1oyuKUHS4c8GQCCRUM= X-Google-Smtp-Source: APXvYqwiTx7TkgXGtcodc4L+QnBPqAQNIRnvG5OariYE8hJwjhwVSVE/TBlptGqkT8F+1+JBrdKo5Q== X-Received: by 2002:adf:fe90:: with SMTP id l16mr3163064wrr.175.1570338090126; Sat, 05 Oct 2019 22:01:30 -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.01.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2019 22:01:29 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 6 Oct 2019 07:01:11 +0200 Message-Id: <20191006050120.26807-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/10] avformat/mpjpegdec: 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/mpjpegdec.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libavformat/mpjpegdec.c b/libavformat/mpjpegdec.c index e653b5cc93..84130ab718 100644 --- a/libavformat/mpjpegdec.c +++ b/libavformat/mpjpegdec.c @@ -113,20 +113,16 @@ static int mpjpeg_read_close(AVFormatContext *s) static int mpjpeg_read_probe(const AVProbeData *p) { - AVIOContext *pb; + AVIOContext pb; int ret = 0; int size = 0; if (p->buf_size < 2 || p->buf[0] != '-' || p->buf[1] != '-') return 0; - pb = avio_alloc_context(p->buf, p->buf_size, 0, NULL, NULL, NULL, NULL); - if (!pb) - return 0; - - ret = (parse_multipart_header(pb, &size, "--", NULL) >= 0) ? AVPROBE_SCORE_MAX : 0; + ffio_init_context(&pb, p->buf, p->buf_size, 0, NULL, NULL, NULL, NULL); - avio_context_free(&pb); + ret = (parse_multipart_header(&pb, &size, "--", NULL) >= 0) ? AVPROBE_SCORE_MAX : 0; return ret; }