[vlc-commits] chromecast: Account for exceptions thrown by constructors

Hugo Beauzée-Luyssen git at videolan.org
Thu Mar 1 11:33:02 CET 2018


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Thu Mar  1 11:29:08 2018 +0100| [de91aed8dc20f5202ff4789a3ab432837fbc7be6] | committer: Hugo Beauzée-Luyssen

chromecast: Account for exceptions thrown by constructors

std::nothrow will just prevent std::bad_alloc from being thrown, but
some of the member variables' constructors will throw std::runtime_error

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=de91aed8dc20f5202ff4789a3ab432837fbc7be6
---

 modules/stream_out/chromecast/cast.cpp | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/modules/stream_out/chromecast/cast.cpp b/modules/stream_out/chromecast/cast.cpp
index 1d869991fd..22532e7e7c 100644
--- a/modules/stream_out/chromecast/cast.cpp
+++ b/modules/stream_out/chromecast/cast.cpp
@@ -1350,10 +1350,17 @@ static int Open(vlc_object_t *p_this)
 
     b_supports_video = var_GetBool(p_stream, SOUT_CFG_PREFIX "video");
 
-    p_sys = new(std::nothrow) sout_stream_sys_t( httpd_host, p_intf, b_supports_video,
-                                                 i_local_server_port );
-    if (unlikely(p_sys == NULL))
+    try
+    {
+        p_sys = new sout_stream_sys_t( httpd_host, p_intf, b_supports_video,
+                                                    i_local_server_port );
+    }
+    catch ( std::exception& ex )
+    {
+        msg_Err( p_stream, "Failed to instantiate sout_stream_sys_t: %s", ex.what() );
+        p_sys = NULL;
         goto error;
+    }
 
     p_intf->setOnInputEventCb(on_input_event_cb, p_stream);
 



More information about the vlc-commits mailing list