avformat/mp3enc: flush buffered packets if referencing fails
authorJames Almer <jamrial@gmail.com>
Fri, 6 Oct 2017 18:55:09 +0000 (15:55 -0300)
committerJames Almer <jamrial@gmail.com>
Sat, 7 Oct 2017 00:59:11 +0000 (21:59 -0300)
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
libavformat/mp3enc.c

index 826878e..8479e24 100644 (file)
@@ -515,20 +515,15 @@ static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt)
         if (mp3->pics_to_write) {
             /* buffer audio packets until we get all the pictures */
             AVPacketList *pktl = av_mallocz(sizeof(*pktl));
-            int ret;
-            if (!pktl) {
+
+            if (!pktl || av_packet_ref(&pktl->pkt, pkt) < 0) {
+                av_freep(&pktl);
                 av_log(s, AV_LOG_WARNING, "Not enough memory to buffer audio. Skipping picture streams\n");
                 mp3->pics_to_write = 0;
                 mp3_queue_flush(s);
                 return mp3_write_audio_packet(s, pkt);
             }
 
-            ret = av_packet_ref(&pktl->pkt, pkt);
-            if (ret < 0) {
-                av_freep(&pktl);
-                return ret;
-            }
-
             if (mp3->queue_end)
                 mp3->queue_end->next = pktl;
             else