From patchwork Sat Sep 19 16:36:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22491 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 551E444A83E for ; Sat, 19 Sep 2020 19:37:31 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4601568B7B7; Sat, 19 Sep 2020 19:37:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0DA1368B771 for ; Sat, 19 Sep 2020 19:37:25 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id e11so8747157wme.0 for ; Sat, 19 Sep 2020 09:37:24 -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=vUb431ldsmT/gjHnZZ/P8J54Mu2mCxf6ZwmVALHE64g=; b=Q6CuOdnxhK8BLTl6Wq2BDN3onx1EsW9HmSqRH7LBbKt9e0gBgBMkl7UsGt2tXYKhkm g0Zk5QWJHqqzKF+HFcl5P30rNcUl2ANUFErrJn3qz7lPz7oTh8mH7mx7XKvrv6NMqIc2 HvZlctkeBegNop7nkYRyuiWpVzBBPNZFm1E2usJnYXI7holUPt18HWyeHvf4HhzCJOsi nr79nLs6cO3AnqB/EjzxUZcYusyU7tIhe9mDknImAvVw9ON5sjUI9262YNMsQ3YYqFnS ++tfZVo1NNqF0w6Sq0joBLuiXeZmjlErtQPE15OGVk1kBXdwnGX4Gkgrnhtgi1mfV48e /y9w== 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=vUb431ldsmT/gjHnZZ/P8J54Mu2mCxf6ZwmVALHE64g=; b=UjlWLeLZbfiIte+7VxH9B+X1tMKwyTI+hFfVy1zTP4h28ioFg7Kk+xwbpEyqHJMtxp Sf6g38kL7haWl9LxeHEy//RFjJawj2OTcFdDzrvkGrBANOQx+hGiOyAAFyeK7V4/WXXQ sajinGSY/WIqibpKy1TZPQ5R+9PJpv2fs0U6bFTjjL+8bvHOprikICbrW+CmCs1wgJhh l7iOcMOM6gKSwWArAn/heSYnYj1hrdycQ25Ofu6+hZ8HjfDw99Qn/60Xjf2v0AdgAM62 LsDCTQJo7Ce6WVN969AabeFqx8+So9DEXeIzlW0cMYA9+AncGYUp5bwSPBJkzfVSpdHj btWg== X-Gm-Message-State: AOAM5308zgBE4auYv4HmIxIMRm2/Ia9xVP3zq76VG8knPqCtG3iJCzFV Eixsf/IPHIefZGJReuh2oAlBJS4JjpY= X-Google-Smtp-Source: ABdhPJxbp+5Eo0+H68tz4BKLesyEIxTamNwT+GMKRXV99K0IAxve+udwP1P0Co8X6V3Z2jOGhXXV5w== X-Received: by 2002:a1c:7418:: with SMTP id p24mr21335668wmc.123.1600533444040; Sat, 19 Sep 2020 09:37:24 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d5sm12451137wrb.28.2020.09.19.09.37.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:23 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:36:01 +0200 Message-Id: <20200919163610.1099233-12-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> References: <20200919163610.1099233-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/21] avformat/dashdec: Fix leak of representation on error 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 parsing a representation fails, it is not added to the list of representations and is therefore not freed in dash_close(); it therefore leaked in most error paths in parse_manifest_representation() (some error paths had (incomplete) code for freeing). This commit fixes freeing the representation in this case. Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 52 +++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 82cb335de9..90d0e89925 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -887,9 +887,8 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, c->max_url_size = aligned(c->max_url_size + (rep_id_val ? strlen(rep_id_val) : 0) + (rep_bandwidth_val ? strlen(rep_bandwidth_val) : 0)); - if (ret == AVERROR(ENOMEM) || ret == 0) { - goto end; - } + if (ret == AVERROR(ENOMEM) || ret == 0) + goto free; if (representation_segmenttemplate_node || fragment_template_node || period_segmenttemplate_node) { fragment_timeline_node = NULL; fragment_templates_tab[0] = representation_segmenttemplate_node; @@ -907,19 +906,12 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, if (initialization_val) { rep->init_section = av_mallocz(sizeof(struct fragment)); - if (!rep->init_section) { - av_free(rep); - ret = AVERROR(ENOMEM); - goto end; - } + if (!rep->init_section) + goto enomem; c->max_url_size = aligned(c->max_url_size + strlen(initialization_val)); rep->init_section->url = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, initialization_val); - if (!rep->init_section->url) { - av_free(rep->init_section); - av_free(rep); - ret = AVERROR(ENOMEM); - goto end; - } + if (!rep->init_section->url) + goto enomem; rep->init_section->size = -1; xmlFree(initialization_val); } @@ -974,23 +966,19 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, fragment_timeline_node = xmlFirstElementChild(fragment_timeline_node); while (fragment_timeline_node) { ret = parse_manifest_segmenttimeline(s, rep, fragment_timeline_node); - if (ret < 0) { - return ret; - } + if (ret < 0) + goto free; fragment_timeline_node = xmlNextElementSibling(fragment_timeline_node); } } } else if (representation_baseurl_node && !representation_segmentlist_node) { seg = av_mallocz(sizeof(struct fragment)); - if (!seg) { - ret = AVERROR(ENOMEM); - goto end; - } + if (!seg) + goto enomem; seg->url = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, NULL); if (!seg->url) { av_free(seg); - ret = AVERROR(ENOMEM); - goto end; + goto enomem; } seg->size = -1; dynarray_add(&rep->fragments, &rep->n_fragments, seg); @@ -1027,9 +1015,8 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, baseurl_nodes, rep_id_val, rep_bandwidth_val); - if (ret < 0) { - return ret; - } + if (ret < 0) + goto free; fragmenturl_node = xmlNextElementSibling(fragmenturl_node); } @@ -1040,16 +1027,14 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, fragment_timeline_node = xmlFirstElementChild(fragment_timeline_node); while (fragment_timeline_node) { ret = parse_manifest_segmenttimeline(s, rep, fragment_timeline_node); - if (ret < 0) { - return ret; - } + if (ret < 0) + goto free; fragment_timeline_node = xmlNextElementSibling(fragment_timeline_node); } } } else { - free_representation(rep); - rep = NULL; av_log(s, AV_LOG_ERROR, "Unknown format of Representation node id[%s] \n", (const char *)rep_id_val); + goto free; } if (rep) { @@ -1090,6 +1075,11 @@ end: xmlFree(rep_framerate_val); return ret; +enomem: + ret = AVERROR(ENOMEM); +free: + free_representation(rep); + goto end; } static int parse_manifest_adaptationset_attr(AVFormatContext *s, xmlNodePtr adaptionset_node)