From patchwork Sun Mar 22 03:47:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18322 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 3DB8244BCD9 for ; Sun, 22 Mar 2020 05:48:39 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1977668B4C0; Sun, 22 Mar 2020 05:48:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8177768B497 for ; Sun, 22 Mar 2020 05:48:31 +0200 (EET) Received: by mail-wm1-f65.google.com with SMTP id a9so7595305wmj.4 for ; Sat, 21 Mar 2020 20:48:31 -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=98yLOsYqPoxCC0FCly7IF3Dutm0dA6gBrPe2P9TC5wM=; b=mpI59y+7rSxRZVqPoK0RfVNfgiM5COc1Q2SqA7PPn5ojjYg4/UsO8Qu8oe5EibiN88 trzFJaArtdh1dSItMj4W0Dpcd9c88eKi6sE3Li44I8W+GGf0+DPaQMU3vt4tu1ry9ZPy pt3sPWyAosZ6CCmZEEsgT0lovx4gkc342LVQDi1Rg4nmnOdaNOB1WKVCjvYbilDDOd2l ufYbD48Uu+yF2UcuzeevTVtX6Tt8TOHUcIEgEe9jXNEbFgd/yMIKBKr4IF37DmQitn7z vLxXG+nIMAl7HJhuGEqGKEdDPgkLeGKOFOnwFgkFqAG7/Leh+2go1Th//gvM4HWGRD4+ iySw== 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=98yLOsYqPoxCC0FCly7IF3Dutm0dA6gBrPe2P9TC5wM=; b=fxcU7pIEyPbdvF4siWHKsgZoQq5l0EwtJ56VJ6lN4ek3MreodAtVotcAe2tzsPyUMy xvD4bqFf/NLuO+o9jPxKj0T4H70FVh16eg5UIU3DN1pQ5iNhM1soPP0rOiRvCDE1Yv65 2kt0Xt0huovq4Q8Zg5VtoZcAVBMyFADQkDZORryWntNFgEYdL4Bc7pff+KKCyBe/Kv5m va3MYqvzOZICOZG4e/e+FaWx5R3cMov26iTmxOlpEmOjyFzFGs+8hQ0kr9EmftYP2j33 R1sn74ymCgvnRmtl9FoZSCEyxlhriaZfCvHc1gewDKIRPEk49EA5En4VvqJPCxxxlVIa 2ftg== X-Gm-Message-State: ANhLgQ01fUye/+e9vjR1zUlJHy4cx19a9IC12vo6Jdh6G+EbOSBK8Ufr S1IQ9F0UBTa2gbORxsxnck/tCCGQ X-Google-Smtp-Source: ADFU+vtAHHs4AQf+BGxOAlyGtCLb+zGJful/nXLb07oriU3UIkfZo1SQBFe4yrPqRfmmp4e90FMMPQ== X-Received: by 2002:a1c:9a43:: with SMTP id c64mr17983343wme.173.1584848910560; Sat, 21 Mar 2020 20:48:30 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id k204sm1530371wma.17.2020.03.21.20.48.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Mar 2020 20:48:29 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 22 Mar 2020 04:47:40 +0100 Message-Id: <20200322034756.29907-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200322034756.29907-1-andreas.rheinhardt@gmail.com> References: <20200322034756.29907-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/21] avformat/matroskadec: Fix memleaks on read_header failure 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" This commit simplifies cleanup after read_header failure: By setting the FF_INPUTFORMAT_HEADER_CLEANUP flag for both the ordinary Matroska demuxer as well as the WebM DASH Manifest demuxer one can remove the "goto fail" in matroska_read_header() as well as an explicit matroska_read_close() in webm_dash_manifest_read_header(); the forward declaration of matroska_read_close() can also be removed. For the Matroska demuxer this fixes a memleak when adding an attached picture fails; for the WebM DASH Manifest demuxer this fixes memleaks because calling matroska_read_close() has been forgotten on several error paths. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskadec.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 4d7fdab99f..31b0a73660 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -749,8 +749,6 @@ static EbmlSyntax matroska_cluster_enter[] = { static const char *const matroska_doctypes[] = { "matroska", "webm" }; -static int matroska_read_close(AVFormatContext *s); - /* * This function prepares the status for parsing of level 1 elements. */ @@ -2837,7 +2835,7 @@ static int matroska_read_header(AVFormatContext *s) while (res != 1) { res = matroska_resync(matroska, pos); if (res < 0) - goto fail; + return res; pos = avio_tell(matroska->ctx->pb); res = ebml_parse(matroska, matroska_segment, matroska); } @@ -2859,7 +2857,7 @@ static int matroska_read_header(AVFormatContext *s) res = matroska_parse_tracks(s); if (res < 0) - goto fail; + return res; attachments = attachments_list->elem; for (j = 0; j < attachments_list->nb_elem; j++) { @@ -2937,9 +2935,6 @@ static int matroska_read_header(AVFormatContext *s) matroska_convert_tags(s); return 0; -fail: - matroska_read_close(s); - return res; } /* @@ -4129,7 +4124,6 @@ static int webm_dash_manifest_read_header(AVFormatContext *s) return -1; } if (!s->nb_streams) { - matroska_read_close(s); av_log(s, AV_LOG_ERROR, "No streams found\n"); return AVERROR_INVALIDDATA; } @@ -4200,7 +4194,8 @@ AVInputFormat ff_matroska_demuxer = { .read_packet = matroska_read_packet, .read_close = matroska_read_close, .read_seek = matroska_read_seek, - .mime_type = "audio/webm,audio/x-matroska,video/webm,video/x-matroska" + .mime_type = "audio/webm,audio/x-matroska,video/webm,video/x-matroska", + .flags_internal = FF_INPUTFORMAT_HEADER_CLEANUP, }; AVInputFormat ff_webm_dash_manifest_demuxer = { @@ -4211,4 +4206,5 @@ AVInputFormat ff_webm_dash_manifest_demuxer = { .read_packet = webm_dash_manifest_read_packet, .read_close = matroska_read_close, .priv_class = &webm_dash_class, + .flags_internal = FF_INPUTFORMAT_HEADER_CLEANUP, };