[vlc-commits] dshow: check CoInitialize() in callbacks

Rémi Denis-Courmont git at videolan.org
Wed Oct 3 19:23:43 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Oct  3 20:18:27 2012 +0300| [bc9856607fdc7f33b4ac63bd09c8c622f6d65b61] | committer: Rémi Denis-Courmont

dshow: check CoInitialize() in callbacks

If the calling thread is using COM with MTA model, then CoInitializeEx()
will fail, and CoUninitialize() will be unbalanced. Ultimately, the
calling thread is likely to crash. (CoInitializeEx() could also fail in
case of memory error, but that is unlikely).

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

 modules/access/dshow/dshow.cpp |   22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/modules/access/dshow/dshow.cpp b/modules/access/dshow/dshow.cpp
index 56a042b..d44aa2c 100644
--- a/modules/access/dshow/dshow.cpp
+++ b/modules/access/dshow/dshow.cpp
@@ -2013,18 +2013,15 @@ static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
 static int FindDevices( vlc_object_t *p_this, const char *psz_name,
                             char ***vp, char ***tp )
 {
-    bool b_audio = !strcmp( psz_name, CFG_PREFIX "adev" );
-
     /* Find list of devices */
     list<string> list_devices;
+    if( SUCCEEDED(CoInitializeEx( NULL, COINIT_APARTMENTTHREADED )) )
+    {
+        bool b_audio = !strcmp( psz_name, CFG_PREFIX "adev" );
 
-    /* Initialize OLE/COM */
-    CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
-
-    FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
-
-    /* Uninitialize OLE/COM */
-    CoUninitialize();
+        FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
+        CoUninitialize();
+    }
 
     unsigned count = 2 + list_devices.size(), i = 2;
     char **values = (char **)xmalloc( count * sizeof(*values) );
@@ -2058,11 +2055,12 @@ static int ConfigDevicesCallback( vlc_object_t *p_this, char const *psz_name,
     char *psz_device = NULL;
     int i_ret = VLC_SUCCESS;
 
+    if( FAILED(CoInitializeEx( NULL, COINIT_APARTMENTTHREADED )) )
+        return VLC_EGENERIC;
+
     if( !EMPTY_STR( newval.psz_string ) )
         psz_device = strdup( newval.psz_string );
 
-    /* Initialize OLE/COM */
-    CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
 
     p_item = config_FindConfig( p_this, psz_name );
 
@@ -2109,9 +2107,7 @@ static int ConfigDevicesCallback( vlc_object_t *p_this, char const *psz_name,
         i_ret = VLC_EGENERIC;
     }
 
-    /* Uninitialize OLE/COM */
     CoUninitialize();
-
     free( psz_device );
     return i_ret;
 }



More information about the vlc-commits mailing list