From patchwork Fri Mar 19 05:59:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26477 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 C2EEC44A856 for ; Fri, 19 Mar 2021 08:02:11 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 34AF568A99E; Fri, 19 Mar 2021 08:00:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8D55068A830 for ; Fri, 19 Mar 2021 07:59:49 +0200 (EET) Received: by mail-ed1-f41.google.com with SMTP id l18so1193714edc.9 for ; Thu, 18 Mar 2021 22:59:49 -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:reply-to :mime-version:content-transfer-encoding; bh=AjAoTCURib04lbD0IcDey1Q4VBKfKVm1Wj8cGpFuVaM=; b=eMp4P427nTi3b0bpxHxm15NCzApm6/ObHMtVX+riHWHh9paqXMWdzVW0BUPRy6Fzlv V+onudQiQ5oqNn/fGWmG6MmRkFmOfWER2QnDwizKH20Z5QFrPUta5OKl2vnLxhB0K2K1 6uzd+mJ+CGZolGligg7obpHHCF+abfgzWaCu32HXWtv+HrqTFdeUETw9gDMTGgfzyBQd Cv/dHYcqzyVrcSBun87BJiR7NvfhRxIorsPinC3NmHI6COjACj68yoeK0Y4qrlOLyfVB RXVcspfSZuCdnANNektLuebwVoe/dc/O+6RF9FcbHx7aTFEWtO1XqxLLygXZYfA3c2KL VDBA== 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:reply-to:mime-version:content-transfer-encoding; bh=AjAoTCURib04lbD0IcDey1Q4VBKfKVm1Wj8cGpFuVaM=; b=BcS0EEtZydsimBrPeBERWCjaBJ9WC3nJaE4U72P6RF4C6hOyHtWULqE1JNTl6X1i+O K1fXRo+SBXDo4t3f7LvQhmIUMJ34EMDXIzJHYS+eKSfdgW3PsJ2Fskp30kmzCC3Zwcko oifF7Mv6iceRhydxaLwPPpbE5nrq7FVbgKdfqARUr7oo5+5NnB4+VB2l3081nGfQNyU2 085ttcls1zPBwNHg3IzgBbwfjUwR9nDNtgCxKDB3TG7ICEE4dlPLQzDQrAzPDeOobQPm hwSvrVPeZcT5sHaL2E8/sUJBWHwavG4Q2r6w9NBPU/G6fqan0bgZqWeBlwZ3i4BpX82x R9Gg== X-Gm-Message-State: AOAM532KEhqBp+OTDwQHsrgJ5hKu3lqIZcs8Uc5a6ge3elKP/4JfHOVf aqebVCe9DCeAwY5ZzAt4EO5xPJ9Jj1AYDg== X-Google-Smtp-Source: ABdhPJwaUPSzxjRAxfEhzNpmMiDNB6ScnNrq4f+1bu5JzVOiG+amCnlMtnPFV9mqEtub3tqlLUCNAA== X-Received: by 2002:a05:6402:35c8:: with SMTP id z8mr7703863edc.341.1616133588923; Thu, 18 Mar 2021 22:59:48 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08960.dynamic.kabel-deutschland.de. [188.192.137.96]) by smtp.gmail.com with ESMTPSA id x17sm3109344ejd.68.2021.03.18.22.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Mar 2021 22:59:48 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 19 Mar 2021 06:59:03 +0100 Message-Id: <20210319055904.2264501-17-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210319055904.2264501-1-andreas.rheinhardt@gmail.com> References: <20210319055904.2264501-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/18] avformat/webpenc: Fix memleak when trailer is never written 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" When the trailer is never written (or when a stream switches from non-animation mode to animation mode mid-stream), a cached packet (if existing) would leak. Fix this by adding a deinit function. Signed-off-by: Andreas Rheinhardt --- AVFormatInternal.parse_pkt is completely unused for muxers, so it can be reused in this muxer and this deinit function removed again. See https://github.com/mkver/FFmpeg/commits/packet_reuse for more. libavformat/webpenc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libavformat/webpenc.c b/libavformat/webpenc.c index d5edf89289..ed8325c02d 100644 --- a/libavformat/webpenc.c +++ b/libavformat/webpenc.c @@ -191,6 +191,13 @@ static int webp_write_trailer(AVFormatContext *s) return 0; } +static void webp_deinit(AVFormatContext *s) +{ + WebpContext *w = s->priv_data; + + av_packet_unref(&w->last_pkt); +} + #define OFFSET(x) offsetof(WebpContext, x) #define ENC AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { @@ -214,6 +221,7 @@ AVOutputFormat ff_webp_muxer = { .init = webp_init, .write_packet = webp_write_packet, .write_trailer = webp_write_trailer, + .deinit = webp_deinit, .priv_class = &webp_muxer_class, .flags = AVFMT_VARIABLE_FPS, };