From patchwork Sat Sep 24 18:24:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 705 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.66 with SMTP id o63csp1168803vsd; Sat, 24 Sep 2016 11:25:10 -0700 (PDT) X-Received: by 10.28.197.138 with SMTP id v132mr7417635wmf.100.1474741510195; Sat, 24 Sep 2016 11:25:10 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 65si1576337wml.9.2016.09.24.11.25.09; Sat, 24 Sep 2016 11:25:10 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0295B6897A4; Sat, 24 Sep 2016 21:24:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oi0-f66.google.com (mail-oi0-f66.google.com [209.85.218.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4D193680368 for ; Sat, 24 Sep 2016 21:24:44 +0300 (EEST) Received: by mail-oi0-f66.google.com with SMTP id n202so11013203oig.2 for ; Sat, 24 Sep 2016 11:25:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=PWdH+0HhF4rT4om73ii2kGsPQI3UCUL6YCisPdT/j9c=; b=xY/zVT1AiFC15OApBHF2vCm4EKpUJIgKnVOMRaLELte7MA7OUlapmF2U9nWmQoeHd8 npMbQ5XFP2yLz4+ugcDSdBMC75Sk/4+YUdUQHqyK0HS0TuAo2Im+IAQIn2dgx2XvFWQw AFfURDnEDBTy5ZmOMyYa4i954boV4OMjJ0POqf7Z0wAfiCfUVPH6gV9K7/Zeg13tLYS2 uJuG+WMc5ztZ7NEFE0h+uGfYH3zWSR2nVBDyk0CPzThUYlurpj9zzqFDwhuv7ONlZTAF dmw1k3zdQPj+S8JQKqGIc3NseoLeeSzLWa/sJK8g36fsh15sbeF0UNIc/P1Yt32bH7uh 6bTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=PWdH+0HhF4rT4om73ii2kGsPQI3UCUL6YCisPdT/j9c=; b=F8/ZtICZhnH1ZviV20sS2KSk2VzQQHOH0/8fNVcYPFAYOrB+kWb/6ZRfG2cH4AdsYB u3lDopWq2r68QcD5PZ5T7wisQiUka4YbI6rT3KxA7JgMYxfeyOv5VBwYc54BiGiYiVid YUUSgvC1UCz1GRnsw615PR2ODcADxTrP0NiBnLSc6T6VePUIpQJ0B1GSbXEiWWew3OHg M24/0QoR1uG/gUwXjhBiGSRfMKhbeb5myFh71p7orDfws8fWLKQpAHzRa1K9WhhinBb8 H44KfMJJBzVBF7oPebhYSt8SDDQOg8SFs3XUfL5jw0kjuziAJM5K5Z7W6l7JLjD+uGyG EMZQ== X-Gm-Message-State: AE9vXwM9tQg9a6YzcpG1BXmxhQ4oAjJsNIRFxLSgI8npTuwLmejhVq4W8Dg+GNtxf2wLNQ== X-Received: by 10.202.80.15 with SMTP id e15mr18001160oib.75.1474741499708; Sat, 24 Sep 2016 11:24:59 -0700 (PDT) Received: from localhost.localdomain ([181.22.44.186]) by smtp.gmail.com with ESMTPSA id 63sm4106795oth.28.2016.09.24.11.24.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 24 Sep 2016 11:24:59 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Sep 2016 15:24:33 -0300 Message-Id: <20160924182433.9160-2-jamrial@gmail.com> X-Mailer: git-send-email 2.9.1 In-Reply-To: <20160924182433.9160-1-jamrial@gmail.com> References: <20160924182433.9160-1-jamrial@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/2] ffmpeg: fix memleak of bitstream filter context on 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Increase the nb_bitstream_filters value as soon as the context is allocated, so if option parsing fails the last context is actually freed. Signed-off-by: James Almer --- ffmpeg_opt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c index 0dfdbd6..40a5090 100644 --- a/ffmpeg_opt.c +++ b/ffmpeg_opt.c @@ -1349,14 +1349,16 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e exit_program(1); } + ost->nb_bitstream_filters++; + if (bsf_options_str && filter->priv_class) { - const AVOption *opt = av_opt_next(ost->bsf_ctx[ost->nb_bitstream_filters]->priv_data, NULL); + const AVOption *opt = av_opt_next(ost->bsf_ctx[ost->nb_bitstream_filters-1]->priv_data, NULL); const char * shorthand[2] = {NULL}; if (opt) shorthand[0] = opt->name; - ret = av_opt_set_from_string(ost->bsf_ctx[ost->nb_bitstream_filters]->priv_data, bsf_options_str, shorthand, "=", ":"); + ret = av_opt_set_from_string(ost->bsf_ctx[ost->nb_bitstream_filters-1]->priv_data, bsf_options_str, shorthand, "=", ":"); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error parsing options for bitstream filter %s\n", bsf_name); exit_program(1); @@ -1364,8 +1366,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e } av_freep(&bsf); - ost->nb_bitstream_filters++; - if (*bsfs) bsfs++; }