From patchwork Sat Oct 19 14:11:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 15846 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 817584498E0 for ; Sat, 19 Oct 2019 17:18:21 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5D47268AD0B; Sat, 19 Oct 2019 17:18:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 512CA68A665 for ; Sat, 19 Oct 2019 17:18:14 +0300 (EEST) Received: by mail-qt1-f195.google.com with SMTP id 3so13583327qta.1 for ; Sat, 19 Oct 2019 07:18:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=nAo9xXeXc7W/NTDpPJmCFJ7Pkttoq+uFpc1h4iV/B5A=; b=i+K/DbMpq+wonm4hkHwGssBUUSeXtiMBApwnnfq2fZbL4FcIzGKqmlqyq2OfIyW8Jy e31ZVYwnoMjVOvY4tamjeGWfN7+2VbLDC/lp84CQZU5DnLb0fFK8wnAxxRgo0MYlGGy6 vnxVnGxnUsKaPmPo+9wwL90ZvjpZC+LeOX+saR8iYWxhQtWoC2VEe9ZSPoevnpWCbIXA 36fmLFW/5IZ5iNzcZeCjmRY/9DQFsctawuV8RfLLyLWk7F7k+AVWw/YBRmy8/ZQBvuiH i3mH8NZvhbxAVcDoLR7GP38yPFe40XPREHf1UmlJpvGFmc0308qOwk3t5ika6A08mHW8 X3rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=nAo9xXeXc7W/NTDpPJmCFJ7Pkttoq+uFpc1h4iV/B5A=; b=KsMmEhGfG4qrz9a/aM8gBDhB8dbjwGwpg8C042uZGQsi9PQ3kUUQ2OpMKokbI0cDbp UOnO9KwanMfQBrvLL9s82hj0ZQmjgNfhyZgdjJbv+3uHU9g59YW+uFKwccFoSKitAPJ1 LiUxLgnGZGr7xVAPEvTvIMyv5lO/8ko+M6sCu9PyfuzM7o2QfWfTboNxNeRwOyCncvj5 VYyqQyKmtndEbdPmF+3BDgFXtvlg27s4lvHsMDAsQEZ2aMP/b4zodmji5jQ72aYUTVwF jJPd+ONdKmCdJKbEychs5908CJf+isV55YMGvBh39gO+mItcTV13PqpAPqgee5gGvGlU EC1w== X-Gm-Message-State: APjAAAW+ic2b/BGzEm4pzgHuLJ2dXWXQANYYbfxnUfdI7HgfeUg1Rswm 10jUCmf5NICvc9B8HJnjBcIEN0iI X-Google-Smtp-Source: APXvYqwBjO+jZJObO2qQ4UXYWykoWKcIkHJbGUwH0WZz7DmHfMcRQYjKdz3gDRdxW7qzolBlHRYFkA== X-Received: by 2002:a37:a655:: with SMTP id p82mr8948767qke.61.1571494312097; Sat, 19 Oct 2019 07:11:52 -0700 (PDT) Received: from localhost.localdomain ([191.83.221.234]) by smtp.gmail.com with ESMTPSA id s75sm5201710qke.14.2019.10.19.07.11.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Oct 2019 07:11:51 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Oct 2019 11:11:07 -0300 Message-Id: <20191019141108.1434-1-jamrial@gmail.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avformat: call AVOutputFormat->deinit() when freeing the context 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Despite the doxy stating that it's called when the muxer is destroyed, this was not true in practice. It's only called by av_write_trailer() and on init() failure. An AVFormatContext may be closed without writing the trailer if errors ocurred while muxing packets, so in order to prevent memory leaks, it should effectively be called when freeing the muxer. Signed-off-by: James Almer --- libavformat/mux.c | 4 +++- libavformat/utils.c | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index 0227c0dadc..719dec8346 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -538,6 +538,8 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) fail: if (s->oformat->deinit) s->oformat->deinit(s); + s->internal->initialized = + s->internal->streams_initialized = 0; return ret; } @@ -1286,7 +1288,7 @@ fail: } } - if (s->oformat->deinit) + if (s->oformat->deinit && s->internal->initialized) s->oformat->deinit(s); s->internal->initialized = diff --git a/libavformat/utils.c b/libavformat/utils.c index 60f0229adc..cfb6d03397 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -4437,6 +4437,9 @@ void avformat_free_context(AVFormatContext *s) if (!s) return; + if (s->oformat && s->oformat->deinit && s->internal->initialized) + s->oformat->deinit(s); + av_opt_free(s); if (s->iformat && s->iformat->priv_class && s->priv_data) av_opt_free(s->priv_data);