avformat/subtitles: Don't increment packet counter prematurely
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sat, 21 Mar 2020 03:50:20 +0000 (04:50 +0100)
committerMichael Niedermayer <michael@niedermayer.cc>
Sun, 22 Mar 2020 12:00:19 +0000 (13:00 +0100)
Do it only if the packet has been successfully allocated in
av_new_packet() -- otherwise on error a completely uninitialized packet
would be unreferenced later.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavformat/subtitles.c

index 172da5d..ad7f689 100644 (file)
@@ -132,9 +132,10 @@ AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q,
         if (!subs)
             return NULL;
         q->subs = subs;
-        sub = &subs[q->nb_subs++];
+        sub = &subs[q->nb_subs];
         if (av_new_packet(sub, len) < 0)
             return NULL;
+        q->nb_subs++;
         sub->flags |= AV_PKT_FLAG_KEY;
         sub->pts = sub->dts = 0;
         memcpy(sub->data, event, len);