From patchwork Mon Mar 2 04:44:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 17997 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 1EDC8449CCD for ; Mon, 2 Mar 2020 06:45:09 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F0F0A68B472; Mon, 2 Mar 2020 06:45:08 +0200 (EET) 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 AEB0C68B0C7 for ; Mon, 2 Mar 2020 06:45:05 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id y17so10787006wrn.6 for ; Sun, 01 Mar 2020 20:45:05 -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=q8LzofkQDxqDeTTPCBDRgHhjNrBTxLp0/9UoR2JH0hM=; b=Pz0PaWhXFMJgwrw+UhCqPAmjRRJAzHUC8sY6sS7WF2P6e6XFWQFgcYYPR5wECOwk3r Ueigoy4N/FvB809ugowzk3oTmZ5ZylK7tt3jNE9EvgZDmoHdQ0AaAOv4IQNXBT7431nu oQe9zIOm/Xl1Pwx21M4hTnD4bwM9kJvoYQm+yH8X62PRmlWxgmypwNCjY/SBAF5hH9EA cFmjda4qV427pruTaXHD0lFyuFPP9Y1U25ihw1ZmpYBhO6E308hy/stivqZW/xVCKYK6 3Dnfeyl8Tx+OSwOl58iMZn/CHdQINI37prGg32mb0TilFQ87+C2uY4UER/Y+WaaRxbq9 9diw== 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=q8LzofkQDxqDeTTPCBDRgHhjNrBTxLp0/9UoR2JH0hM=; b=WusPS42jaw2NTLtuDAVqM45RBSsnbIU4PuUfUTVlzRppDgj8EtTb8U6icK9Yp5n0zO hT5X1R5SUOI78GFJNVJRyiiRIzl9K5DMTGfzbG2N0CZrM2IPtVsWpxmbLuVve2DDWj8T cjb319PFoey4yIk68yTxxh2CK0fQ39eCLPJEVzrALeT0bNT1yRDf+TVqWpjohKoanQwF vxcvizaC2VmknRN2/Y8wSBJtepkJvuJwPPuVKA6GB4zfyQt67XIn3JV6HzPfkh5I7R1D mQhTesJxTH5zKXYoOnlMLBKOBCLCefkeR1O5qV53Ffxr1OiKy5hS3rS/WcOfoQ4xzVuk kUGQ== X-Gm-Message-State: APjAAAULGpVfCNCg6r0/RFytB6S2MbyaDeKIqX7H35DKa7PdYGxhrbv/ 6o53EQsYu/hG5upLPIiocT8BTyW3 X-Google-Smtp-Source: APXvYqwzyu+c93pSfTz/ofP8HlWTvaEMoFF7/Lvwps5/zaPgj79gJBr+d9Tpx7RwRPqCi3KgrMHhkw== X-Received: by 2002:adf:e910:: with SMTP id f16mr19606033wrm.20.1583124305001; Sun, 01 Mar 2020 20:45:05 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1ab4b.dynamic.kabel-deutschland.de. [188.193.171.75]) by smtp.gmail.com with ESMTPSA id s22sm13130229wmc.16.2020.03.01.20.45.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 20:45:04 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Mar 2020 05:44:43 +0100 Message-Id: <20200302044445.14842-11-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200302043520.14165-1-andreas.rheinhardt@gmail.com> References: <20200302043520.14165-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/17] avformat/webm_chunk: Add deinit function 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" This fixes memleaks if an error happens after one of the allocations in init; or if the trailer isn't written (e.g. because there was an error when writing a packet). Signed-off-by: Andreas Rheinhardt --- libavformat/webm_chunk.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/libavformat/webm_chunk.c b/libavformat/webm_chunk.c index efdce62391..6ffe952eff 100644 --- a/libavformat/webm_chunk.c +++ b/libavformat/webm_chunk.c @@ -258,13 +258,22 @@ static int webm_chunk_write_trailer(AVFormatContext *s) if (!oc->pb) { ret = chunk_start(s); if (ret < 0) - goto fail; + return ret; } av_write_trailer(oc); - ret = chunk_end(s, 0); -fail: - avformat_free_context(oc); - return ret; + return chunk_end(s, 0); +} + +static void webm_chunk_deinit(AVFormatContext *s) +{ + WebMChunkContext *wc = s->priv_data; + + if (!wc->avf) + return; + + ffio_free_dyn_buf(&wc->avf->pb); + avformat_free_context(wc->avf); + wc->avf = NULL; } #define OFFSET(x) offsetof(WebMChunkContext, x) @@ -296,6 +305,7 @@ AVOutputFormat ff_webm_chunk_muxer = { .write_header = webm_chunk_write_header, .write_packet = webm_chunk_write_packet, .write_trailer = webm_chunk_write_trailer, + .deinit = webm_chunk_deinit, .priv_class = &webm_chunk_class, }; #endif