Commit bc985660 authored by Rémi Denis-Courmont's avatar 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).
parent 72b2a691
...@@ -2013,18 +2013,15 @@ static int DemuxControl( demux_t *p_demux, int i_query, va_list args ) ...@@ -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, static int FindDevices( vlc_object_t *p_this, const char *psz_name,
char ***vp, char ***tp ) char ***vp, char ***tp )
{ {
bool b_audio = !strcmp( psz_name, CFG_PREFIX "adev" );
/* Find list of devices */ /* Find list of devices */
list<string> list_devices; list<string> list_devices;
if( SUCCEEDED(CoInitializeEx( NULL, COINIT_APARTMENTTHREADED )) )
{
bool b_audio = !strcmp( psz_name, CFG_PREFIX "adev" );
/* Initialize OLE/COM */ FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
CoInitializeEx( NULL, COINIT_APARTMENTTHREADED ); CoUninitialize();
}
FindCaptureDevice( p_this, NULL, &list_devices, b_audio );
/* Uninitialize OLE/COM */
CoUninitialize();
unsigned count = 2 + list_devices.size(), i = 2; unsigned count = 2 + list_devices.size(), i = 2;
char **values = (char **)xmalloc( count * sizeof(*values) ); char **values = (char **)xmalloc( count * sizeof(*values) );
...@@ -2058,11 +2055,12 @@ static int ConfigDevicesCallback( vlc_object_t *p_this, char const *psz_name, ...@@ -2058,11 +2055,12 @@ static int ConfigDevicesCallback( vlc_object_t *p_this, char const *psz_name,
char *psz_device = NULL; char *psz_device = NULL;
int i_ret = VLC_SUCCESS; int i_ret = VLC_SUCCESS;
if( FAILED(CoInitializeEx( NULL, COINIT_APARTMENTTHREADED )) )
return VLC_EGENERIC;
if( !EMPTY_STR( newval.psz_string ) ) if( !EMPTY_STR( newval.psz_string ) )
psz_device = strdup( newval.psz_string ); psz_device = strdup( newval.psz_string );
/* Initialize OLE/COM */
CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
p_item = config_FindConfig( p_this, psz_name ); p_item = config_FindConfig( p_this, psz_name );
...@@ -2109,9 +2107,7 @@ static int ConfigDevicesCallback( vlc_object_t *p_this, char const *psz_name, ...@@ -2109,9 +2107,7 @@ static int ConfigDevicesCallback( vlc_object_t *p_this, char const *psz_name,
i_ret = VLC_EGENERIC; i_ret = VLC_EGENERIC;
} }
/* Uninitialize OLE/COM */
CoUninitialize(); CoUninitialize();
free( psz_device ); free( psz_device );
return i_ret; return i_ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment