From patchwork Thu Apr 4 16:27:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Diego Felix de Souza via ffmpeg-devel X-Patchwork-Id: 12615 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 7502C447A0F for ; Thu, 4 Apr 2019 19:27:51 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5A47C68AA7D; Thu, 4 Apr 2019 19:27:51 +0300 (EEST) 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 8719B68AA6F for ; Thu, 4 Apr 2019 19:27:44 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id w1so4613710wrp.2 for ; Thu, 04 Apr 2019 09:27:44 -0700 (PDT) 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=8DYuOwuflZrjYwmaexhqFwgzGTfqwY5hPqPPkU/Qmwg=; b=Do+Q0hTFyBmCQtN1AMzi8GqiHt25s+VbBZsuYjfiY1siwOh/EVU6SduL+Jkvzyt3Kc c9ESgxfcqrTAiklBZCwDplcrNgUi8yAX1qfeQTL9bWMeflhdf4dIJtiuYKoSBiVRwY/p 9EL165byE7/eX+5jPrmfVllWRTAaxFMPzoM3p5TD48y9vdxXEv31yLUwYSfpTT5lsqRM L+nUpe82TmUernArNZHKPQ+ZH864bSiOBp6KbxplfnfurQKVFadv10UHYEWjsxBKBuLo cvc9HlkQKnB72rq/q2gRJ5I3pfK72lYZX9esxszDTXx4r5vLpJvpzHtNr79klnw/B4+E T8pQ== X-Gm-Message-State: APjAAAVMywZUQ3kt9ujAwf7FQdgjWewdzrdMAp8ji5PzVlJwa3xFFVOi QRnS588GlLV7ic8PLVF8Tl+YhVRo X-Google-Smtp-Source: APXvYqxTvCjdMcYPnwSIyrSZUeMRQ6yNI+MOGmk/HAdXOx+hzuaV1r8JNWt5/HOP/YxE50Hh2uVeEg== X-Received: by 2002:adf:f90c:: with SMTP id b12mr4915494wrr.63.1554395263811; Thu, 04 Apr 2019 09:27:43 -0700 (PDT) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.googlemail.com with ESMTPSA id t81sm38639748wmb.5.2019.04.04.09.27.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Apr 2019 09:27:43 -0700 (PDT) To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Apr 2019 18:27:03 +0200 Message-Id: <20190404162703.2608-1-andreas.rheinhardt@googlemail.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <8980e64f-aa67-1ddd-91a6-a37f9db9e74f@googlemail.com> References: <8980e64f-aa67-1ddd-91a6-a37f9db9e74f@googlemail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/matroskaenc: Fix memleak 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: , X-Patchwork-Original-From: Andreas Rheinhardt via ffmpeg-devel From: Diego Felix de Souza via ffmpeg-devel Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Audio packets with size zero, but with side-data currently lead to memleaks, in the Matroska muxer, because they are not properly freed: They are currently put into an AVPacket in the MatroskaMuxContext to ensure that the necessary audio is always available for a new cluster, but are only written and freed when their size is > 0. As the only use we have for such packets consists in updating the CodecPrivate it makes no sense to store these packets at all and this is how this commit solves the memleak. Fixes track ticket #7827. Signed-off-by: Andreas Rheinhardt --- Could some kind soul please run Valgrind to check that it really fixes the memleak from #7827? (I have thought about whether all zero-sized packets (not necessarily audio packets only) should be discarded at this point, but if I am not mistaken, then WebVTT subtitles can be side-data-only.) libavformat/matroskaenc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index b9f99c4463..06f3aeb46d 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2534,7 +2534,8 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) // buffer an audio packet to ensure the packet containing the video // keyframe's timecode is contained in the same cluster for WebM if (codec_type == AVMEDIA_TYPE_AUDIO) { - ret = av_packet_ref(&mkv->cur_audio_pkt, pkt); + if (pkt->size > 0) + ret = av_packet_ref(&mkv->cur_audio_pkt, pkt); } else ret = mkv_write_packet_internal(s, pkt, 0); return ret;