From patchwork Fri Oct 25 01:27:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15940 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 D51AC449AF2 for ; Fri, 25 Oct 2019 04:35:44 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B840A68AAB8; Fri, 25 Oct 2019 04:35:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B519E689E51 for ; Fri, 25 Oct 2019 04:35:38 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id t16so452501wrr.1 for ; Thu, 24 Oct 2019 18:35: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:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ny6qJRbPmBbOVGNkDpoFvXg7WEu9rQo1FTNcdIhHmM4=; b=oH7v71gmfPT2WCjrdrF+Zz0G6eLZvIOQJA5PN106vV9NkblYxlrkI7Mdb+vdpA0sxd 64nkqWcuk+EQKX+Hiw3TU7Qm12rdXbQh0psdvzYIKKiaqrz64gU5OdJRwNXw7gOy0e6p jQATrSrgLS+l9I9O4VSlKXq8gQnCoa5kj/2b3ty6KsEynsiSLhecCFHUJoJvXBj7nSW3 YYXH1w2hDMDB8FR+ZrjXTDtQb0US/Zcare/NfsvTSTnm1nNH82aRZET/VpOuCUC/mPpt lx90TKWsvM2O+vkVLbmRR4SO0jyeW3RZeNsHnNMSTT600a6N9ltqc+ufMynAgSSHH1x3 dbkw== 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=Ny6qJRbPmBbOVGNkDpoFvXg7WEu9rQo1FTNcdIhHmM4=; b=hzbKeE96nTVLq217mny+uG/Sdr+FWjGzHkTcG7Io2z8EEGUi+hafGZqx/Y1QBApIR6 9gTfqlLjabMwjlTIaZ9SDkivUW+uDnzPEGDs8ab4GKiPuDWeZ1gxXzjxXPPG7ovRqgMb ZC8RWMFXJScTMni8UOwIOCdWNUr/ESrQ93Gn8bfA8OOxf75UqbaOR3Pyv+t8yh1HxnlU lZADvAeyfmfZhXexcmVpVhfSNWsrD4p/03Ux7QT0yRwHDwtIRg2Tg5KqtAK0uQHcb/r7 QZfWq1QceAPk+MkPs569RzUF2QYaw7x4mABa0Sxt82R7wM7SBdbEG1wDXTtC7kpw9X/L WBIg== X-Gm-Message-State: APjAAAV4gLmfXukBZkMTVGlERuXlaFJUB/rxehx0oBpKnng2Ra/KS/Cc UAQ362TzxbO4G5joKmje9f2zw/cz X-Google-Smtp-Source: APXvYqyCBkcbnP45k3/M5/xSusnA50jlFrEwiLhu0ZeDep0HnGOCVrfYT0WeJCqrrrRx+IAooAPFZg== X-Received: by 2002:a5d:65cf:: with SMTP id e15mr377785wrw.391.1571967013442; Thu, 24 Oct 2019 18:30:13 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08937.dynamic.kabel-deutschland.de. [188.192.137.55]) by smtp.gmail.com with ESMTPSA id o4sm614841wre.91.2019.10.24.18.30.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 18:30:12 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 25 Oct 2019 03:27:39 +0200 Message-Id: <20191025012739.29734-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191025012739.29734-1-andreas.rheinhardt@gmail.com> References: <20191024174202.GB27353@michaelspb> <20191025012739.29734-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] 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 --- libavformat/mpeg.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c index e6bc6700de..73ade71d95 100644 --- a/libavformat/mpeg.c +++ b/libavformat/mpeg.c @@ -715,6 +715,18 @@ static int vobsub_probe(const AVProbeData *p) return 0; } +static int vobsub_read_close(AVFormatContext *s) +{ + int i; + MpegDemuxContext *vobsub = s->priv_data; + + 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; @@ -898,7 +910,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; } @@ -1023,18 +1036,6 @@ static int vobsub_read_seek(AVFormatContext *s, int stream_index, min_ts, ts, max_ts, flags); } -static int vobsub_read_close(AVFormatContext *s) -{ - int i; - MpegDemuxContext *vobsub = s->priv_data; - - 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(MpegDemuxContext, sub_name), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM }, { NULL }