diff mbox

[FFmpeg-devel,v2,3/8] avformat/utils: Preserve integrity of linked list

Message ID 20190819215624.49795-3-andreas.rheinhardt@gmail.com
State Accepted
Headers show

Commit Message

Andreas Rheinhardt Aug. 19, 2019, 9:56 p.m. UTC
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 <andreas.rheinhardt@gmail.com>
---
No changes since last time.

 libavformat/utils.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Michael Niedermayer Sept. 18, 2019, 8:59 p.m. UTC | #1
On Mon, Aug 19, 2019 at 11:56:19PM +0200, Andreas Rheinhardt wrote:
> 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 <andreas.rheinhardt@gmail.com>
> ---
> No changes since last time.

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 564be02334..b93d80588d 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;
             }
         }