From patchwork Sat Apr 11 23:56:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18883 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 9CF6344B711 for ; Sun, 12 Apr 2020 02:57:17 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8977E68B85D; Sun, 12 Apr 2020 02:57:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0EE7F68B6F8 for ; Sun, 12 Apr 2020 02:57:11 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id s8so6392513wrt.7 for ; Sat, 11 Apr 2020 16:57:11 -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 :mime-version:content-transfer-encoding; bh=tTLwnM4GvYx847sUiJtGfQQPUBgHZJilWF5UYZVEIXI=; b=Y5ZghDNmo6m8HJ+wG+Nq+mpxUg0OwJDg4lcQq2e5MKQlVtNOLoAqh1UPKr/cxiIh5i 2brV5U0Jzp3/2BCLcEFNRVKtY1+7yoPObRkDBJehmDKKGiXz+HKqrSvz2x40nx+bgRRH xuojPFzuP1dUJaKkKFd4DaZIesvhZUalfPIQ/YUR8xR0DUFMRslqj8Yn2YlEtne8669M JOI/Ti2uuYIWGkjvVPW7I23tyDH4oOCq6VJ9euXcQQntLqDVT5B3A4cWW5WACoTIQu2a YX/6cf9YVU1k+Xv3gi4lLkoLTTd8iVmn5S/VNvUhArbDf6wOaDsZ3Qyw6ObrurGHccWi KHyg== 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=tTLwnM4GvYx847sUiJtGfQQPUBgHZJilWF5UYZVEIXI=; b=qXu7d8+5iuHFPJ6PXDqZhxSfml0i3kb8W+yHN7CkEmDqsH8AOQ/fVZX66ScnYPbccf Ze5LVOGTgUqcPpz3/+ycNf8qBP0yWVSO3EZ/RYU3fM4XEGxE8J/RbN9OurMbUlJY4Z9Q lfoUHAmhvVKS6Oo7GvhL+wqmcflKFR4RGtcbAt4Swpi8XeCHuBVBQFR/ou4VK7oAe9BP disv4vjp5fz4LQiVGGSU1TZnQDZY4SHI9OpM8V0qO4fAjkPExtN03CU2NUvV69MNHZ0W Sk0rKo1fRWWshMp1USaZGmGLesXq7ippyPrSo4InaJ4mi1DK6l605jIm0juhXjA/H8rs FG3A== X-Gm-Message-State: AGi0PubmCavWqbanUebKJ8YXUZvrxbAclo4cYPHBLA5gPfxWze5LR6A7 D7jgptFAaqSWGTK/kDTyRZQR96Dl X-Google-Smtp-Source: APiQypK5oZjn6/4MeRBOshg1hJDQb1HJxi24bi6nMNGFOLObXn2elk9/kN0yFoKT+5FEh7VtgTygIA== X-Received: by 2002:a5d:6647:: with SMTP id f7mr9553370wrw.41.1586649430102; Sat, 11 Apr 2020 16:57:10 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id s7sm8817442wrt.2.2020.04.11.16.57.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2020 16:57:09 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 12 Apr 2020 01:56:42 +0200 Message-Id: <20200411235642.18193-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200411235642.18193-1-andreas.rheinhardt@gmail.com> References: <20200411235642.18193-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/6] avformat/mux: Fix leaks on error when writing noninterleaved uncoded frames 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 writing uncoded frames in noninterleaved mode fails at the preparatory steps (i.e. before it reaches write_packet()), the packet would not be unreferenced and the frame would leak. This is fixed by unreferencing the packet in write_uncoded_frame_internal() instead. This also makes it possible to remove the unreferencing in write_packet() itself: In noninterleaved mode frames are now freed in write_uncoded_frame_internal(), while they are freed in interleaved mode when their containing packet gets unreferenced (like normal packets). Signed-off-by: Andreas Rheinhardt --- Just resending because of merge conflicts. libavformat/mux.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index 78fe2336cb..35b92edd27 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -743,7 +743,6 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) AVFrame **frame = (AVFrame **)pkt->data; av_assert0(pkt->size == sizeof(*frame)); ret = s->oformat->write_uncoded_frame(s, pkt->stream_index, frame, 0); - av_packet_unref(pkt); } else { ret = s->oformat->write_packet(s, pkt); } @@ -1318,6 +1317,7 @@ static int write_uncoded_frame_internal(AVFormatContext *s, int stream_index, AVFrame *frame, int interleaved) { AVPacket pkt, *pktp; + int ret; av_assert0(s->oformat); if (!s->oformat->write_uncoded_frame) { @@ -1350,8 +1350,11 @@ static int write_uncoded_frame_internal(AVFormatContext *s, int stream_index, pkt.flags |= AV_PKT_FLAG_UNCODED_FRAME; } - return interleaved ? av_interleaved_write_frame(s, pktp) : - av_write_frame(s, pktp); + ret = interleaved ? av_interleaved_write_frame(s, pktp) : + av_write_frame(s, pktp); + if (pktp) + av_packet_unref(pktp); + return ret; } int av_write_uncoded_frame(AVFormatContext *s, int stream_index,