From patchwork Thu Dec 26 10:53:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 16965 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 15F33449EFF for ; Thu, 26 Dec 2019 12:54:13 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0369D68AB2C; Thu, 26 Dec 2019 12:54:13 +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 2142D688157 for ; Thu, 26 Dec 2019 12:54:06 +0200 (EET) Received: by mail-wm1-f65.google.com with SMTP id q9so4074417wmj.5 for ; Thu, 26 Dec 2019 02:54:06 -0800 (PST) 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=pvaOjZoxpWmgSB6+xNT6f0EeqjL794LZSgYeseaXOPs=; b=RGnmyAqJ95YTBW6o5qCc5hRtQZexKTYEOjkGWgTd1aV4CfotVusGaE4mJ8lQ6gMFoe MwlTxStsgOAhS4pQC0TS4+P2ztS3HzXeQMiELE31x9Vni8dKQfOewag3fc3Gl3vs36qF 4eZopLWlawBAGX96lcS56SUIejv4G3AKey4zkfFFjS9GOCydNrcdqk1adgSGgTbTuHDq ZFxORoTEPsuSTjK7imMDyX5lUbWFK0bvXoghFxvtjrGaZRX+zKGbTE8u6k4zVqcn9R1o Y2+8mzg1Pybj5LW2OpWZyUeYJe1Z8o/Lc8T5w5DeJECyfWdRTxSYcJI0HNre//H87ixz oYUg== 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=pvaOjZoxpWmgSB6+xNT6f0EeqjL794LZSgYeseaXOPs=; b=pbB1fk3hTujQphCv67EN6Ksvv/uRacpa2MMMxE/Alhgx20bh/8u2RM+QFpwQaSePGz I1HtwhG6bDvFhEI8deNMpNLnrZAYAEPN2bfl+klF76kahAwhVh57fJIHJXwC0g6+3BSn GHofDVEX+8qgOmY+Ymns9L3184+tS7Q6TslSqsQukf9vbr2gFGUFy5kmlYY1RRpiwhF1 gIV5ZeWnL9PZflJyM2PvlRgCt/WQkPCOIm+VXYNS2bukhOdBT44TFuZDdGzUGOQY0uhZ vFbH3RLLOULj+9qXQcOeHs9jxZh5t81S9xp0BT7Rk0eHzI+jgM/B3HpRbFX1ha8GkCzM p6lg== X-Gm-Message-State: APjAAAU16HSmLDm0bbg9vhhfH1pOEBnsxBBVNhOJGHSC2HYoJwfXWdvv Sf402NOJ4eNw6lEzkFPij5mwFt81 X-Google-Smtp-Source: APXvYqyrJzmcSO3s8OFSh17wiSYFHOiEszyKkQeQ3SaIPIqMxjMpX/3Du03Qt4qEGQMYEwHgm6FGlg== X-Received: by 2002:a7b:cf2d:: with SMTP id m13mr13544890wmg.163.1577357645222; Thu, 26 Dec 2019 02:54:05 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc10203.dynamic.kabel-deutschland.de. [188.193.2.3]) by smtp.gmail.com with ESMTPSA id c68sm7997618wme.13.2019.12.26.02.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Dec 2019 02:54:04 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 26 Dec 2019 11:53:28 +0100 Message-Id: <20191226105342.11175-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191226105342.11175-1-andreas.rheinhardt@gmail.com> References: <20191226105342.11175-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/17] avformat/smoothstreaming: Fix memleaks on errors 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 an AVFormatContext could be allocated, but white-/blacklists couldn't be copied, the AVFormatContext would leak as it was only accessible through a local variable that goes out of scope when one goes to fail. Furthermore, in case writing a header of a submuxer failed, the options used for said call could leak. Both of these memleaks have been fixed. Signed-off-by: Andreas Rheinhardt --- libavformat/smoothstreamingenc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c index 2faf1e7897..0e4f531f90 100644 --- a/libavformat/smoothstreamingenc.c +++ b/libavformat/smoothstreamingenc.c @@ -332,12 +332,11 @@ static int ism_write_header(AVFormatContext *s) goto fail; } - ctx = avformat_alloc_context(); + os->ctx = ctx = avformat_alloc_context(); if (!ctx || ff_copy_whiteblacklists(ctx, s) < 0) { ret = AVERROR(ENOMEM); goto fail; } - os->ctx = ctx; ctx->oformat = oformat; ctx->interrupt_callback = s->interrupt_callback; @@ -357,12 +356,13 @@ static int ism_write_header(AVFormatContext *s) av_dict_set_int(&opts, "ism_lookahead", c->lookahead_count, 0); av_dict_set(&opts, "movflags", "frag_custom", 0); - if ((ret = avformat_write_header(ctx, &opts)) < 0) { + ret = avformat_write_header(ctx, &opts); + av_dict_free(&opts); + if (ret < 0) { goto fail; } os->ctx_inited = 1; avio_flush(ctx->pb); - av_dict_free(&opts); s->streams[i]->time_base = st->time_base; if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { c->has_video = 1;