From patchwork Sun Aug 23 09:50:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21831 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 7FA9844B698 for ; Sun, 23 Aug 2020 12:51:14 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5EC9968973D; Sun, 23 Aug 2020 12:51:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DF9616881E6 for ; Sun, 23 Aug 2020 12:51:06 +0300 (EEST) Received: by mail-ej1-f65.google.com with SMTP id l2so2185133eji.3 for ; Sun, 23 Aug 2020 02:51:06 -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=mGIE19aEfiw847+EY/W9X5Eo0Pd7Sx53kLc/sQ39vs4=; b=bR5cxMr0ML0agImegHbQyCQp3l3llYaLLwLsM9PPhbF6DJedq8zUsNKDd33NpJqRB5 K1GApnDaCNdblPV4TIshl91r+ApyUG6UWPl5WkW67UAdkXhJDRVFayxldL7LdqlyC5xI s2f36TZPUABDwjvTO9wNdPZFtpX2bW8y5Vu6H4yeXAF/FIWf1ARzBJ/8Cs0EZvKxDKC9 vBH8RQYJqmY0JqCrdC5BCSGdp4kMXx+ES2wC6JBzlPqSyae2nXwAMLM+C9FoZF9rLuzc 6UvRDpFOPvIKCtSuz9Mk9a53ZBcjWGtoPzVDNFY5oRTxGG5eaHjj5cXAqfZ22IbJguzg SQlQ== 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=mGIE19aEfiw847+EY/W9X5Eo0Pd7Sx53kLc/sQ39vs4=; b=kawmPKW976GV6m+5Y9muKJPKfbtXS6/Rd5vlaKGyhxCGasYFsUSswVECbe+N6SbvEq he15t6Xa2z0hPfoA3qcVtM0CV0SB9MOK4f3H5fTmbi5GXvMxJL7JH42RFrvgzdTY9JzP ZZw3gRyAPnuEjIqfT1A0ox92u8qaX5JbiwRwmsmojxJNzi5WlcVN3CQwJJzD7iCUoLlZ /oFjvJUfrdOdWPqorGr0TS0eKmyMf+w/MWEox4yZQ6uMJr6POrhRpCUAoHQa+uFd4t0R XPdb0Dr2wtjfIcaxfAc2fGXbAWeNYcAyXhQizoavxPwICdtuA6x3qzWiwr1nXcQd8zei uIUw== X-Gm-Message-State: AOAM532SBvfi2URiXhXPsCr4YIIVqn4IIJErIxUQ4GCBA7H/QlyhDdfL 1W5ehPJL+Y26gNEblpkaak0dnvbtDic= X-Google-Smtp-Source: ABdhPJzElRY3WV3ijL5Q0RusJ3YGy6wL+laPPvoCczvS1ebPhw2ESIjzW4+3uQbdSF9wlUBdvdRKng== X-Received: by 2002:a17:906:600f:: with SMTP id o15mr798815ejj.529.1598176266097; Sun, 23 Aug 2020 02:51:06 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id v10sm5256022eda.87.2020.08.23.02.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Aug 2020 02:51:05 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 23 Aug 2020 11:50:39 +0200 Message-Id: <20200823095039.18851-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200822230434.11347-1-andreas.rheinhardt@gmail.com> References: <20200822230434.11347-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/7] avfilter/graphparser: Fix memleak when linking filters fails 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" Parsing labeled outputs involves a check for an already known match (a labeled input with the same name) to pair them together. If yes, it is attempted to create a link between the two filters; in this case the AVFilterInOuts have fulfilled their purpose and are freed. Yet if creating the link fails, these AVFilterInOuts have up until now not been freed, although they had already been removed from their respective lists (which means that they are not freed automatically). In other words: They leak. This commit fixes this. This fixes ticket #7084. Said ticket contains an example program to reproduce a leak. It can also be reproduced with ffmpeg alone, e.g. with the complex filters "[0]null[1],[2]anull[0]" or with "[0]abitscope[0]". All of these three examples involve media type mismatches which make it impossible to create the links. The bug could also be triggered by other means, e.g. failure to allocate the necessary AVFilterLink. Signed-off-by: Andreas Rheinhardt --- libavfilter/graphparser.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c index f55737f8c7..d72e65c09a 100644 --- a/libavfilter/graphparser.c +++ b/libavfilter/graphparser.c @@ -372,15 +372,14 @@ static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs, match = extract_inout(name, open_inputs); if (match) { - if ((ret = link_filter(input->filter_ctx, input->pad_idx, - match->filter_ctx, match->pad_idx, log_ctx)) < 0) { - av_free(name); - return ret; - } + ret = link_filter(input->filter_ctx, input->pad_idx, + match->filter_ctx, match->pad_idx, log_ctx); av_freep(&match->name); av_freep(&name); av_freep(&match); av_freep(&input); + if (ret < 0) + return ret; } else { /* Not in the list, so add the first input as an open_output */ input->name = name;