From patchwork Thu Sep 10 01:39:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22244 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 8FF1944A365 for ; Thu, 10 Sep 2020 04:39:56 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 75A3068B9A6; Thu, 10 Sep 2020 04:39:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AF40B68B910 for ; Thu, 10 Sep 2020 04:39:49 +0300 (EEST) Received: by mail-wm1-f47.google.com with SMTP id q9so4031953wmj.2 for ; Wed, 09 Sep 2020 18:39: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:mime-version :content-transfer-encoding; bh=zwvG4dY+akXCXcBmBBT6KnVKNrThlR7tDRTf6/voroA=; b=XZ86MmAor+4T4uime0ygqqDbl5diqm8q7glc9TESRiM+evXUvg/4/7rBD9FbwJnaW/ 6veWW9ph4u+wvOQPBEiQgxOUbHsqRq/wJjZ7sIO4gQhMnNC9k2r5oLfmTGDxWKpEkVCQ gzfeQ23ILrT4WU8qyseqd53y5lApDn2C/oOroV9voPgmfXVmu3gheOblg0BczseQAzIl 3MBl7h2wHF0UO4kuMNh9VTgFQn4bs/8/loyEEzR2WXpxT0MjIS2EdhCPvYJM4lC+XhPD fberuVSNDymcGQfxvHLvRk3gr/P5vuhXxo0XbePHCVyGMwEk53BS1pzme0yJhaQtX0+F 2PJA== 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:mime-version :content-transfer-encoding; bh=zwvG4dY+akXCXcBmBBT6KnVKNrThlR7tDRTf6/voroA=; b=Q2ZuT0wjWQef2dYFpvQEdF/7wMNZAuJ2WXs8naVQXhpIOVYHywsjsCMxGjbe5k4141 pVMEADXWtBkAGBhE52Mye5xCuHZdpBs99j5ZmVJ45wAlquXroPjqKEaKT+wwoXtZufwn D8/ONcYJ+QABVEJGkEsuZ/Q5kKdwJwQf/eZqTZvig240KgEI2tkJYXoBbOjZTHq2lDtH Bk6AYN4cquTBssfhNokbsZUkXtfzEoLGOyW801Va5gXqQwnrGBgbTflEzTanM63Sj6zz Q91AvDbvA5GRO7l4M1uPqkO1Xod5m3RfONU3kItTw9cSHlK/PrQHxdZKAetFdJcMJwzO grGw== X-Gm-Message-State: AOAM533vCo+q86u8XFy8rgfVk1FFVjyA8G+Qr9hyHpHISfR0HfSEtN5R rngvkoW77VkFqg5vOqAn55UC9CPloyw= X-Google-Smtp-Source: ABdhPJyzhhsXR8k1clKykoZSo/valQOOhJORXw3LRsOak0mWqGxCx7lqGbtQdYboappNudi4jHg+HA== X-Received: by 2002:a1c:a3c4:: with SMTP id m187mr6399708wme.159.1599701988891; Wed, 09 Sep 2020 18:39:48 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id n4sm1176380wmd.26.2020.09.09.18.39.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 18:39:48 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 10 Sep 2020 03:39:39 +0200 Message-Id: <20200910013941.14444-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avfilter/src_movie: Remove unneeded resetting of AVPacket 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" av_read_frame() already returns clean packets on error. Signed-off-by: Andreas Rheinhardt --- libavfilter/src_movie.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c index 6e210d1df0..b9b940684d 100644 --- a/libavfilter/src_movie.c +++ b/libavfilter/src_movie.c @@ -495,7 +495,6 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id) } else { ret = av_read_frame(movie->format_ctx, &movie->pkt0); if (ret < 0) { - av_init_packet(&movie->pkt0); /* ready for flushing */ *pkt = movie->pkt0; if (ret == AVERROR_EOF) { movie->eof = 1; From patchwork Thu Sep 10 01:39:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22245 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 CCA8F44A510 for ; Thu, 10 Sep 2020 04:40:15 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B343668B9B5; Thu, 10 Sep 2020 04:40:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B071F68B8A9 for ; Thu, 10 Sep 2020 04:40:08 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id k15so4860192wrn.10 for ; Wed, 09 Sep 2020 18:40:08 -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=ap7g7oHpbGMcURrYQaAF5TAw1HoWP4N8J8do//ue6nA=; b=DwAtoylSAspav4aavaFnZaFWJOyzPiyXrXIWnS2shvXct46WfDU5FGAv68FgdHRLcp q40BGZbGV+EtKFSrcJ0LdjiqaUT0KLDUXbHk8g8L4rgMzfT2tr8qEUOr9+UAHRzluVpK +DHSBWMSTjTvem6bRVYcI5JIofW7UyRID7NAi0uFYKYAnWMOQKNaYvcK43lMig8LMcCn pZFvy++eBPcNuawu5m5QCuJ5O6g6QycySU1SK4PcCM8D44zOsYEt2LgL3vEKvLu5J+bU Rk+Rbj5MoDCWtkbLsthr5qGJhXSltMsIXI1ENZWHeCrMEzmkXfL+B6IdHEh2QdSdljxr dU/w== 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=ap7g7oHpbGMcURrYQaAF5TAw1HoWP4N8J8do//ue6nA=; b=Kl+UWcyIblwR4QoNV5uqlYuopd5zj4Nf2O8BWd/Wcfuaus+F1v4huSbiQocWqGzjad IT6r/AFuF/w2OumgBaZQH8nHC6+d35yIZ/mq5Jp93vVtvlJNGjbfFo/UqzPvWcA+RNs0 9NN/EaH3CKA13Rkx1I+K1gH/os/ZxD9YYUNHFJ0BaHo9um3qTNQ5waXHvvp7bMNdRE6R sFGtXgBitVZD1j1cELV9xy8YQXByMNKnloT15A2veawAthBivvUJwUhHeKZ1L9pcLSUd rB2LxOnqTmIsK2itOJ6telqY/uocw+X+VvqfUU+SzevfceQwvjapMkjX5YAuhkuj/AGM f1qA== X-Gm-Message-State: AOAM532z6KlPf7P7/V2bd19D1Y+YloWl8UlW40nP1g/RjdfF6KYgmDnm Y1KdxCPtdfSBHAAYZzMCabVzrXME30E= X-Google-Smtp-Source: ABdhPJxKx56JZ56isPy+Le9lINobJVdG6YNc9LIzZp/gsfqBssD0v+aaYc/3UXTzVz6pIU4jxaVUIw== X-Received: by 2002:a5d:46c5:: with SMTP id g5mr6703402wrs.416.1599702007892; Wed, 09 Sep 2020 18:40:07 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id n4sm1176380wmd.26.2020.09.09.18.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 18:40:07 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 10 Sep 2020 03:39:40 +0200 Message-Id: <20200910013941.14444-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200910013941.14444-1-andreas.rheinhardt@gmail.com> References: <20200910013941.14444-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avfilter/src_movie: Remove unnecessary secondary AVPacket 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" The movie and amovie filters currently use two packets. One of the two, pkt0, is the owner of the returned packet; it is also the destination packet for av_read_frame(). The other one pkt is initially (i.e. after av_read_frame()) a copy of pkt0; copy means that the contents of both are absolutely the same: They both point to the same AVBufferRef and the same side data. This violation of the refcounted packet API is only possible because pkt is not considered to own its data. Only pkt0 is ever unreferenced. The reason for pkt's existence seems to be historic: The API used for decoding audio (namely avcodec_decode_audio4()) could consume frames partially, i.e. it could return multiple frames for one packet and therefore it returned how much of the input buffer had been consumed. The caller was then supposed to update the packet's data and size pointer to reflect this and call avcodec_decode_audio4() again with the updated packet to get the next frame. But before the introduction of refcounted AVPackets where knowledge and responsibility about what to free lies with the underlying AVBuffer such a procedure required a spare packet (or one would need to record the original data and size fields separately to restore them before freeing the packet; notice that this code has been written when AVPackets still had a destruct field). But these times are long gone, so just remove the secondary AVPacket. Signed-off-by: Andreas Rheinhardt --- It seems that the avcodec_decode_audio4() lost the ability to output multiple frames per packet in 061a0c14bb5767bca72e3a7227ca400de439ba09. Am I right? libavfilter/src_movie.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c index b9b940684d..75ac3bfaf6 100644 --- a/libavfilter/src_movie.c +++ b/libavfilter/src_movie.c @@ -71,7 +71,7 @@ typedef struct MovieContext { AVFormatContext *format_ctx; int eof; - AVPacket pkt, pkt0; + AVPacket pkt; int max_stream_index; /**< max stream # actually used for output */ MovieStream *st; /**< array of all streams, one per output */ @@ -493,25 +493,21 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id) pkt->stream_index = movie->st[out_id].st->index; /* packet is already ready for flushing */ } else { - ret = av_read_frame(movie->format_ctx, &movie->pkt0); + ret = av_read_frame(movie->format_ctx, pkt); if (ret < 0) { - *pkt = movie->pkt0; if (ret == AVERROR_EOF) { movie->eof = 1; return 0; /* start flushing */ } return ret; } - *pkt = movie->pkt0; } } pkt_out_id = pkt->stream_index > movie->max_stream_index ? -1 : movie->out_index[pkt->stream_index]; if (pkt_out_id < 0) { - av_packet_unref(&movie->pkt0); - pkt->size = 0; /* ready for next run */ - pkt->data = NULL; + av_packet_unref(pkt); return 0; } st = &movie->st[pkt_out_id]; @@ -536,9 +532,7 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id) if (ret < 0) { av_log(ctx, AV_LOG_WARNING, "Decode error: %s\n", av_err2str(ret)); av_frame_free(&frame); - av_packet_unref(&movie->pkt0); - movie->pkt.size = 0; - movie->pkt.data = NULL; + av_packet_unref(pkt); return 0; } if (!ret || st->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) @@ -546,11 +540,8 @@ static int movie_push_frame(AVFilterContext *ctx, unsigned out_id) pkt->data += ret; pkt->size -= ret; - if (pkt->size <= 0) { - av_packet_unref(&movie->pkt0); - pkt->size = 0; /* ready for next run */ - pkt->data = NULL; - } + if (pkt->size <= 0) + av_packet_unref(pkt); if (!got_frame) { if (!ret) st->done = 1; From patchwork Thu Sep 10 01:39:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22246 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 2BBFD44A510 for ; Thu, 10 Sep 2020 04:40:19 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0294A68B9C0; Thu, 10 Sep 2020 04:40:19 +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 803E968B8A9 for ; Thu, 10 Sep 2020 04:40:09 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id w5so4869294wrp.8 for ; Wed, 09 Sep 2020 18:40:09 -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=Dqhf/5EqKW4arB+rhxAIxnRanbwK9ES9+1utuyKLwy4=; b=MaWEFS4ecRUdWZ0b6vAIn7hq6+745nDTC18tSxqQdbiXybW7sIa7fwZ4hGfxN3xFww VerrjEmQNSr6pF2n2FmfFMuNO5ma51LwkD3mv75VARkTjd7TSsSZUyK97bAWWJ+IeqSk i/fXf57/i0e61hozhAhBX6qChlVBZbtpY7f9ehJoU0CC9mtLAvaCmPskTIF4gpa1tkOc wNGW5yL7ara6Urj5tWspn9QiSf3J1tu2+oVN6C4712+kFOcsxE1DYtKA0AtD0EcbLgUI uXALwkcfjGgCaWRKfih3AaGkLENlaPkkuXj/u2A6yCyiSJ3uTpaSMkecqxuuXlYuKihb +2Nw== 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=Dqhf/5EqKW4arB+rhxAIxnRanbwK9ES9+1utuyKLwy4=; b=mgcgeFbPDUanGH60BpdFEYbwHADPEETVNncrOx2i2BvmL8QDXJAxdIBssz21hIw4qo iEGf4Y/0/2qtLIOkDjYAsHo/YV+8lzie2FV/Vox6KeKgPM8eDr9I6dLuTZcj3NNEvNE2 8RKu1zdTsIOXGsqjA9rAvvfTxv+PTdmi0s7EBirWhuhfG2BdgLM/C7eCnRqEtR0M/5hH lJkz+CUcrKyPXjmrgbLmeywU1VO3mxtzTF9hwB4iDAp1PspkSFWilQX2SuVHFaMCUgDl uNgBgVWStCibwMnQidQsDyt1SZ8x+6nkL3bPiU6uSYcxqY/VRqkg5bczj3CgiQCrBajo mt5g== X-Gm-Message-State: AOAM533TQtITpC5QUxwyw7GcPGT70mAYcp1PsJGwUW2J8/j1bZGqIBu4 R8RvkBcAylDJ2X68OvXoEdpcn1RfL0U= X-Google-Smtp-Source: ABdhPJyhr0wWHAmu6ngrMaYnbiZmczu7u/7aZXIfZ+y71o1cmhz6H041Q3XKmFc5fmZGPzv7HiZD4w== X-Received: by 2002:a05:6000:124d:: with SMTP id j13mr6977426wrx.182.1599702008845; Wed, 09 Sep 2020 18:40:08 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id n4sm1176380wmd.26.2020.09.09.18.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 18:40:08 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 10 Sep 2020 03:39:41 +0200 Message-Id: <20200910013941.14444-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200910013941.14444-1-andreas.rheinhardt@gmail.com> References: <20200910013941.14444-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avfilter/src_movie: Fix leak of packet upon error 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 allocating the AVFrame to contain a decoded frame fails, the AVPacket containing the data intended to be decoded leaks. This commit fixes this. Signed-off-by: Andreas Rheinhardt --- libavfilter/src_movie.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c index 75ac3bfaf6..d83cb6d1e4 100644 --- a/libavfilter/src_movie.c +++ b/libavfilter/src_movie.c @@ -344,6 +344,7 @@ static av_cold void movie_uninit(AVFilterContext *ctx) } av_freep(&movie->st); av_freep(&movie->out_index); + av_packet_unref(&movie->pkt); if (movie->format_ctx) avformat_close_input(&movie->format_ctx); }