From patchwork Tue Oct 22 13:16:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15901 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 5A7FF448B82 for ; Tue, 22 Oct 2019 16:17:24 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 442F268AF28; Tue, 22 Oct 2019 16:17:24 +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 BA39768AF00 for ; Tue, 22 Oct 2019 16:17:15 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id p4so18037369wrm.8 for ; Tue, 22 Oct 2019 06:17:15 -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=mION0x5pl1/jO43x5pCNZx7ib+UY0VZl3FMo55g5QARYsf3U62D6kH1QDIBGW1Y1Mb pgtlkirjlxKETnNdNJ2kER/xkpAcITLMjfKD4dFuIcz8JanwUyRPisgrMlJjthtw0IxQ beMxaKj5lzrzQEmMltrfELwYoJwHUacAGQnIUPWGHoVyGfZozkA5AIZAC9EUIym/Pg7I EWJ7JrrZSvfEvyRbMLM9oEatN5Md1HqF8Ly28JDvGr5fEBG9oaAJ0+XqI9Ayl3MECps4 eQJolr8cA2ZY/qYDBQWEP/jLlkABWH/ySXqpKeiETXjjs5GH+uJK/EWe8YVPB/AEQ0A8 sYGw== 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=OmsUVUuu3/cYwSpIx8udZTAUrOfMbcjfs0SBCxwrc4ODOUw3mNY0k0UUsgRlgEW8RE F726FgPIk9JVVP8VTo/zsYuli5teVKabG0RtB/gzMnm3CjWe5GyAEjKRJGtfh+um9ojv xGXW5XlQ+/gZHucrZmo77vwglAzYOyEPEKSXV2SG1uFiaFy7Ac/l06jEf20OMljgwatG e7Kl0OA12A02VxTh3y3HMgBE7uKdpmuQ7Ou5SHWj4IjJp79n2q0QMHrn0UxPXU0cl0db hKKzkBfl9G2UtEoN4yK01sIzlOs2fpeLISS1vEeHy6Urnd0+WkUaLkBUTjQGCfyO5WeL kPqA== X-Gm-Message-State: APjAAAXkWmkHVFBmtmg2Z/c3I4VDT91Iari8f6KunQSWTBlbIPGRrGEA W8Lcaapu0/6F92dHHzcIa6TZ4m23 X-Google-Smtp-Source: APXvYqyTNsSJvAYwdUDi6nT+DcBQYS3G5DUhCSnP5Z8lcQnMICU8CdbVP7xiRBbEF8IOEwDfartunA== X-Received: by 2002:adf:c448:: with SMTP id a8mr3588450wrg.233.1571750235075; Tue, 22 Oct 2019 06:17:15 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08937.dynamic.kabel-deutschland.de. [188.192.137.55]) by smtp.gmail.com with ESMTPSA id o70sm25074520wme.29.2019.10.22.06.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2019 06:17:14 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 22 Oct 2019 15:16:44 +0200 Message-Id: <20191022131645.8394-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191022131645.8394-1-andreas.rheinhardt@gmail.com> References: <20191022131645.8394-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/5] avformat/mpeg: Fix memleak II 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 }