avformat/nutenc: free all missing dynamic AVIOContext on header writing failure
authorJames Almer <jamrial@gmail.com>
Sat, 19 Oct 2019 17:37:27 +0000 (14:37 -0300)
committerJames Almer <jamrial@gmail.com>
Sat, 19 Oct 2019 17:42:23 +0000 (14:42 -0300)
Fixes part of ticket #8316

Signed-off-by: James Almer <jamrial@gmail.com>
libavformat/nutenc.c

index 4d10e70..d212f0c 100644 (file)
@@ -637,8 +637,10 @@ static int write_headers(AVFormatContext *avctx, AVIOContext *bc)
         if (ret < 0)
             return ret;
         ret = write_streamheader(avctx, dyn_bc, nut->avf->streams[i], i);
-        if (ret < 0)
+        if (ret < 0) {
+            ffio_free_dyn_buf(&dyn_bc);
             return ret;
+        }
         put_packet(nut, bc, dyn_bc, 1, STREAM_STARTCODE);
     }
 
@@ -653,12 +655,13 @@ static int write_headers(AVFormatContext *avctx, AVIOContext *bc)
         if (ret < 0)
             return ret;
         ret = write_streaminfo(nut, dyn_bc, i);
-        if (ret < 0)
-            return ret;
         if (ret > 0)
             put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE);
-        else
+        else {
             ffio_free_dyn_buf(&dyn_bc);
+            if (ret < 0)
+                return ret;
+        }
     }
 
     for (i = 0; i < nut->avf->nb_chapters; i++) {