From patchwork Wed Dec 4 12:37: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: 16589 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 1AD8F449DB0 for ; Wed, 4 Dec 2019 14:37:46 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F006468B1E9; Wed, 4 Dec 2019 14:37:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 91A7468AF4E for ; Wed, 4 Dec 2019 14:37:38 +0200 (EET) Received: by mail-wm1-f41.google.com with SMTP id s14so7727618wmh.4 for ; Wed, 04 Dec 2019 04:37:38 -0800 (PST) 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=sC+TZoejJvhoXYVNEb4vc0TW5EtMH91CxmJkm753Y8U=; b=LyHt0vHzUaqb7ll9cDHBiiSBGbFH19/TmI2xAO/zeG9sGMcPD7tBP4oP+eWsJ038au S/m6rxv5cIVz5WVcVKhKiV4rPN5coMr8hCbGLclQCG0NxH3TG23Rhgq/IS64vdbJysox +SDsNZPuhSXDyOhRoqv+xlGIsW06JmPhprt5pCOQVY2Kp5N+Cqvl12ibz88CD+i83MUX 8Mc2+u1FrVIRoFJO+L1bo7Hjnq8EMEQp/cuD8WO5Tk9+sFB3vQ8Wmhhc3GFIQudXhpeK y11u404rNCnOYr9pf4gtNTD4yUDm4I9lpaETKjtrl18opCk2OTEx7FhfxvcaJqUWBTDC /PUg== 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=sC+TZoejJvhoXYVNEb4vc0TW5EtMH91CxmJkm753Y8U=; b=lwresC0fXD8XHG89U4yffzbdLZu8ZtPiiRnYsft/qZaBbjeGryEAIT2CFIfjiGMiPY LUGJdA5YQvPAaWKVacNcSgFg2gf9YBz2vKQAC/rS45dH+j48FJwYtaFxNY2tsLxCqBuF 0HiXR7afjCtTAXTzii4gPzpmEFQikIpzwa9ssj8lLI/RM2/5dRrlH2spRf7A+VrFmhmv itZM2EKFyQrSId9d+7TZUqs4JcQKAMsffPxC2j+D/DSMWGAgW/zdNG5Ajz4mN2IN8GQe fqgQT6WCqcnLRHqSd7PItuhvPHqa78os6DVtjVkigqUufxx194oOmm0ksv0NXqHMbXel GW4A== X-Gm-Message-State: APjAAAXAVA90nm1KE8RrObtjh8cuOlqMofGbXVC34bwDSnL5xtqcC7am Ry45XWZetMpo6xvEl+qpkpwgoMFF X-Google-Smtp-Source: APXvYqzWz2HWG7Fa6O41OUhrErdszOj6wYJIWrIsDyQmHvLET12t/rjUOKzTVRNmcgkNr6BVegXDMg== X-Received: by 2002:a7b:c7cc:: with SMTP id z12mr32997196wmk.115.1575463057916; Wed, 04 Dec 2019 04:37:37 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08e23.dynamic.kabel-deutschland.de. [188.192.142.35]) by smtp.gmail.com with ESMTPSA id v15sm6295872wmh.24.2019.12.04.04.37.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2019 04:37:37 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 4 Dec 2019 13:37:14 +0100 Message-Id: <20191204123714.27765-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191204123714.27765-1-andreas.rheinhardt@gmail.com> References: <20191204123714.27765-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avformat/mpeg: Fix leaks of AVFormatContext and subtitle packets 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" If an error happens in vobsub_read_header() after allocating the AVFormatContext intended to read the sub-file, both the AVFormatContext as well as the data in the subtitles queues leaks. This has been fixed. Signed-off-by: Andreas Rheinhardt --- Supersedes https://ffmpeg.org/pipermail/ffmpeg-devel/2019-October/252075.html Resending because of merge conflicts. libavformat/mpeg.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c index e4fe16c7d2..e61851bba5 100644 --- a/libavformat/mpeg.c +++ b/libavformat/mpeg.c @@ -713,6 +713,18 @@ static int vobsub_probe(const AVProbeData *p) return 0; } +static int vobsub_read_close(AVFormatContext *s) +{ + VobSubDemuxContext *vobsub = s->priv_data; + int i; + + for (i = 0; i < s->nb_streams; i++) + ff_subtitles_queue_clean(&vobsub->q[i]); + if (vobsub->sub_ctx) + avformat_close_input(&vobsub->sub_ctx); + return 0; +} + static int vobsub_read_header(AVFormatContext *s) { int i, ret = 0, header_parsed = 0, langidx = 0; @@ -896,7 +908,8 @@ static int vobsub_read_header(AVFormatContext *s) memcpy(par->extradata, header.str, header.len); } end: - + if (ret < 0) + vobsub_read_close(s); av_bprint_finalize(&header, NULL); return ret; } @@ -1021,18 +1034,6 @@ static int vobsub_read_seek(AVFormatContext *s, int stream_index, min_ts, ts, max_ts, flags); } -static int vobsub_read_close(AVFormatContext *s) -{ - VobSubDemuxContext *vobsub = s->priv_data; - int i; - - for (i = 0; i < s->nb_streams; i++) - ff_subtitles_queue_clean(&vobsub->q[i]); - if (vobsub->sub_ctx) - avformat_close_input(&vobsub->sub_ctx); - return 0; -} - static const AVOption options[] = { { "sub_name", "URI for .sub file", offsetof(VobSubDemuxContext, sub_name), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM }, { NULL }