From patchwork Fri Aug 16 17:01:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 14554 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 C6D71447AC1 for ; Fri, 16 Aug 2019 20:02:40 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AD89768AC00; Fri, 16 Aug 2019 20:02:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 91AC168AB99 for ; Fri, 16 Aug 2019 20:02:34 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id 207so4580622wma.1 for ; Fri, 16 Aug 2019 10:02:34 -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=JucTbVGW6Qhfi+ZxRZbda5TVR0n8v+tqQ70yufokesc=; b=R5s/N+zWSQyUS2gu2jTyKAGb8uZYFDsW71buCQCJnY4Jj30sI3cst1g/3XNX/SxR+P hHxsCUNpCxrInY9LOMLmAeV2jSlN2BwlxI5UCaNnoA6sCjyt7L6ChdcyLM7gifb54Uof kiXuCbzoeQ+7hj64J2iMvc/+7bU/4deDF3Xo78BkqyRFFBFhaq0M45DE1f6nEmiZWvh2 pS8FB15SFTefpAkP6LA9lB/M2MOUnP3UzFvUNz2O/u9s7IubPLluE5Tllf/wo2o8d1s+ O5xmIKJIOdCzUFNWlPTPMeL/c6X6iFEQtUtNDN2U9Aii8YVW1g4rD+ZL0xg6aMEHE2li B+oQ== 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=JucTbVGW6Qhfi+ZxRZbda5TVR0n8v+tqQ70yufokesc=; b=RCOCW5oOJVVIX9SjYAaVGqW+v6fI3z4YpS/grElax8WXJtWV+tAjF17NQEXaktjSLA eOWALVV72aNlbMRGkzTgDwIvqZcRZdvaV4co7GQsDothN81wqlcc1HYDwbiTp6TUXfv5 +iPj9TsqL0qoPBKL91TXV/K+Zh/IxC2gtQGKdBK2xt438BolRPffxyVu8xGtCx1VDucu 7SIpuaQYEWjl06/6NEtdYdwUx27SjnFzituxQvZdHh8WnimpFYd/+rRc5D3gkeHPhQYF 1mIKRfocgO7dODAflDYFK4Ow9FErmP3gsdNt/Moex4kamT1R9+PWD3upMNPrfT+IWwF9 okFA== X-Gm-Message-State: APjAAAWOpjQve+/tddb53aq4wHMx9JCVWw+UyFpj+2H6oJ/k6Fa4KUX5 TWTuPgmazQr1zYCS9CDw9k4j9Jq9 X-Google-Smtp-Source: APXvYqznBDVOqb7aQKnm+RQEkzOzZk6CR8Ci6YEYevAZwtBiuVeidnUf/766cdrZqJWp1r+ge1W4SQ== X-Received: by 2002:a1c:2ec6:: with SMTP id u189mr8253003wmu.67.1565974953891; Fri, 16 Aug 2019 10:02:33 -0700 (PDT) Received: from localhost.localdomain (ipbcc08b69.dynamic.kabel-deutschland.de. [188.192.139.105]) by smtp.gmail.com with ESMTPSA id w15sm5130795wmi.19.2019.08.16.10.02.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2019 10:02:33 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Aug 2019 19:01:35 +0200 Message-Id: <20190816170135.57811-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190816164314.57764-1-andreas.rheinhardt@gmail.com> References: <20190816164314.57764-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avformat/utils: Preserve integrity of linked list 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" 1. Instead of relying on ff_packet_list_get to get the oldest element in an AVPacketList, ff_read_packet used its own ad-hoc code. Said code forgot to set the end of the list to NULL if the last element of the list has been removed, thereby leaving the list in an inconsistent state. 2. Furthermore, if the list was not empty, the oldest element of the list would always be copied into another packet structure before it was known whether the oldest entry of the list would be removed. This makes the ownership confusing and potentially copies unnecessarily. Both of these issues have been fixed. ff_packet_list_get is used now. Signed-off-by: Andreas Rheinhardt --- libavformat/utils.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index a902841ad5..9e87ae3f10 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -837,15 +837,14 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) AVPacketList *pktl = s->internal->raw_packet_buffer; if (pktl) { - *pkt = pktl->pkt; - st = s->streams[pkt->stream_index]; + st = s->streams[pktl->pkt.stream_index]; if (s->internal->raw_packet_buffer_remaining_size <= 0) if ((err = probe_codec(s, st, NULL)) < 0) return err; if (st->request_probe <= 0) { - s->internal->raw_packet_buffer = pktl->next; + ff_packet_list_get(&s->internal->raw_packet_buffer, + &s->internal->raw_packet_buffer_end, pkt); s->internal->raw_packet_buffer_remaining_size += pkt->size; - av_free(pktl); return 0; } }