avformat/dashenc : Handled error from ff_http_do_new_request() cleanly
authorkjeyapal@akamai.com <kjeyapal@akamai.com>
Fri, 16 Nov 2018 08:57:11 +0000 (14:27 +0530)
committerKarthick J <kjeyapal@akamai.com>
Thu, 22 Nov 2018 06:36:27 +0000 (12:06 +0530)
libavformat/dashenc.c

index 2c872f9..e51ffaf 100644 (file)
@@ -174,6 +174,8 @@ static int dashenc_io_open(AVFormatContext *s, AVIOContext **pb, char *filename,
         URLContext *http_url_context = ffio_geturlcontext(*pb);
         av_assert0(http_url_context);
         err = ff_http_do_new_request(http_url_context, filename);
+        if (err < 0)
+            ff_format_io_close(s, pb);
 #endif
     }
     return err;
@@ -183,6 +185,9 @@ static void dashenc_io_close(AVFormatContext *s, AVIOContext **pb, char *filenam
     DASHContext *c = s->priv_data;
     int http_base_proto = filename ? ff_is_http_proto(filename) : 0;
 
+    if (!*pb)
+        return;
+
     if (!http_base_proto || !c->http_persistent) {
         ff_format_io_close(s, pb);
 #if CONFIG_HTTP_PROTOCOL
@@ -356,7 +361,8 @@ static int flush_dynbuf(OutputStream *os, int *range_length)
     // write out to file
     *range_length = avio_close_dyn_buf(os->ctx->pb, &buffer);
     os->ctx->pb = NULL;
-    avio_write(os->out, buffer + os->written_len, *range_length - os->written_len);
+    if (os->out)
+        avio_write(os->out, buffer + os->written_len, *range_length - os->written_len);
     os->written_len = 0;
     av_free(buffer);