From patchwork Sat Sep 19 16:36:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22497 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 1738C44A83E for ; Sat, 19 Sep 2020 19:37:37 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F167268B82C; Sat, 19 Sep 2020 19:37:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1DABF68B7A0 for ; Sat, 19 Sep 2020 19:37:29 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id c18so8582399wrm.9 for ; Sat, 19 Sep 2020 09:37:29 -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=ifRBpz+i9hyzoFUGpIi3gevLnrpiOXxbkrE5/JTgj/s=; b=Eolvs89tei6hYtqcKFwj59xP+hy4mIFkCWdgAqx4lMie5SKOSsiDwyE6Z5cDzW+IWc UVJOMN+4Mcti2QYBgYkW+wokjd6YNo4oKAPLAhuFMKlB+TYqL8cRv0e8uCmv66zvUnPc 2KQ6fUpjBkTfNOZyj1HLYVvdWuOPKEH4gz1xHSXQhOjPRIs1vNAhi2oVsVOsTqkQ+WcZ zag6gh/Usp54SR+63g+eZcf0RUXrHd2aBlByGBoTPE6XW6Cd+6s2RGcPPgnreMASkO3C baqdMvRo9iRa5YFkqVWYLwiAYA74vIxdUjswIoVpNIHb8F7WpI7Ny1UZdyrpGonW71pY c0RQ== 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=ifRBpz+i9hyzoFUGpIi3gevLnrpiOXxbkrE5/JTgj/s=; b=NPkgkl4gpYsCzJPq0AWO9TVD5GsGWAeSsZvNUr3eURhBi2lhUSA6iAE8+mf4GwwJxV eHHomTifpmKvaieWzBOsix0K80KRKWqToen3NMUiKzf3Rkj2ndEqLKbn+XSYmy+1Z3hN 3ieciEXxkkt/pThI7n0RDSpn7nbAqEUm7F4k3zf4YVgrxyiIJzQ7fCke4DuwCVezhYLD AQSdbpK7crs0bMYxluC84cexTkQjQxWoHrH981VjHOFNtpNIsYb1Ji0NNJeK6Rl6tKuE ks/NM7VSdWU16BoqBasLHqWubMKJzG1qH9QzLO5jkgVRCOIBIYZKQffU+/JAg8g/exY0 XznQ== X-Gm-Message-State: AOAM530jPIMbuxBOLvcQFxl+bS8QFm8qKEcCPs0JUKGE3Jo8Ie31S3YW H86c/xP6C3XeWgmbr1ecbN7C/dbsXdY= X-Google-Smtp-Source: ABdhPJwWluKSO7czxM0+o2Y0i8xBmLRzBqelxyaj4HsfYb2u/OTOhaLpw+767LbMQyKvOovIsPb7TQ== X-Received: by 2002:adf:eb86:: with SMTP id t6mr43562530wrn.411.1600533448050; Sat, 19 Sep 2020 09:37:28 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 09:37:27 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Sep 2020 18:36:04 +0200 Message-Id: <20200919163610.1099233-15-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 15/21] avformat/dashdec: Fix memleaks on error to add representation to dynarray 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" Up until now, the DASH demuxer used av_dynarray_add() to add audio/video/subtitles representations to arrays. Yet av_dynarray_add() frees the array upon failure, leading to leaks of its elements; furthermore, the element to be added leaks, too. This has been fixed by using av_dynarray_add_nofree() instead and by freeing the elements that could not be added to the list. Furthermore, errors from this are now checked and returned. Signed-off-by: Andreas Rheinhardt --- libavformat/dashdec.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 4d4611ef04..e1554d077b 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -605,6 +605,7 @@ static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati char *media_val = NULL; char *range_val = NULL; int max_url_size = c ? c->max_url_size: MAX_URL_SIZE; + int err; if (!av_strcasecmp(fragmenturl_node->name, (const char *)"Initialization")) { initialization_val = xmlGetProp(fragmenturl_node, "sourceURL"); @@ -648,7 +649,11 @@ static int parse_manifest_segmenturlnode(AVFormatContext *s, struct representati av_free(seg); return AVERROR(ENOMEM); } - dynarray_add(&rep->fragments, &rep->n_fragments, seg); + err = av_dynarray_add_nofree(&rep->fragments, &rep->n_fragments, seg); + if (err < 0) { + free_fragment(&seg); + return err; + } } } @@ -660,6 +665,7 @@ static int parse_manifest_segmenttimeline(AVFormatContext *s, struct representat { xmlAttrPtr attr = NULL; char *val = NULL; + int err; if (!av_strcasecmp(fragment_timeline_node->name, (const char *)"S")) { struct timeline *tml = av_mallocz(sizeof(struct timeline)); @@ -685,7 +691,11 @@ static int parse_manifest_segmenttimeline(AVFormatContext *s, struct representat attr = attr->next; xmlFree(val); } - dynarray_add(&rep->timelines, &rep->n_timelines, tml); + err = av_dynarray_add_nofree(&rep->timelines, &rep->n_timelines, tml); + if (err < 0) { + av_free(tml); + return err; + } } return 0; @@ -975,13 +985,15 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, seg = av_mallocz(sizeof(struct fragment)); 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) { + ret = av_dynarray_add_nofree(&rep->fragments, &rep->n_fragments, seg); + if (ret < 0) { av_free(seg); - goto enomem; + goto free; } + seg->url = get_content_url(baseurl_nodes, 4, c->max_url_size, rep_id_val, rep_bandwidth_val, NULL); + if (!seg->url) + goto enomem; seg->size = -1; - dynarray_add(&rep->fragments, &rep->n_fragments, seg); } else if (representation_segmentlist_node) { // TODO: https://www.brendanlong.com/the-structure-of-an-mpeg-dash-mpd.html // http://www-itec.uni-klu.ac.at/dash/ddash/mpdGenerator.php?fragmentlength=15&type=full @@ -1051,18 +1063,20 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, switch (type) { case AVMEDIA_TYPE_VIDEO: - dynarray_add(&c->videos, &c->n_videos, rep); + ret = av_dynarray_add_nofree(&c->videos, &c->n_videos, rep); break; case AVMEDIA_TYPE_AUDIO: - dynarray_add(&c->audios, &c->n_audios, rep); + ret = av_dynarray_add_nofree(&c->audios, &c->n_audios, rep); break; case AVMEDIA_TYPE_SUBTITLE: - dynarray_add(&c->subtitles, &c->n_subtitles, rep); + ret = av_dynarray_add_nofree(&c->subtitles, &c->n_subtitles, rep); break; default: av_log(s, AV_LOG_WARNING, "Unsupported the stream type %d\n", type); break; } + if (ret < 0) + goto free; } }