[vlc-commits] bdagraph: Do not leak STA

Hugo Beauzée-Luyssen git at videolan.org
Fri Jul 21 19:40:05 CEST 2017


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Fri Jul 21 14:29:35 2017 +0200| [440658435dfaa870337ba121557d628ae5825f30] | committer: Hugo Beauzée-Luyssen

bdagraph: Do not leak STA

Fix #18183

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

 modules/access/dtv/bdagraph.cpp | 17 +++++++++++++----
 modules/access/dtv/bdagraph.hpp | 13 +++++++++++++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/modules/access/dtv/bdagraph.cpp b/modules/access/dtv/bdagraph.cpp
index 1fd51a8395..ea36bc9ff9 100644
--- a/modules/access/dtv/bdagraph.cpp
+++ b/modules/access/dtv/bdagraph.cpp
@@ -149,6 +149,7 @@ dvb_device_t *dvb_open (vlc_object_t *obj)
 
 void dvb_close (dvb_device_t *d)
 {
+    ComContext ctx( COINIT_APARTMENTTHREADED );
     delete d->module;
     delete d;
 }
@@ -174,27 +175,32 @@ bool dvb_get_pid_state (const dvb_device_t *, uint16_t)
 
 unsigned dvb_enum_systems (dvb_device_t *d)
 {
+    ComContext ctx( COINIT_APARTMENTTHREADED );
     return d->module->EnumSystems( );
 }
 
 float dvb_get_signal_strength (dvb_device_t *d)
 {
+    ComContext ctx( COINIT_APARTMENTTHREADED );
     return d->module->GetSignalStrength( );
 }
 
 float dvb_get_snr (dvb_device_t *d)
 {
+    ComContext ctx( COINIT_APARTMENTTHREADED );
     return d->module->GetSignalNoiseRatio( );
 }
 
 int dvb_set_inversion (dvb_device_t *d, int inversion)
 {
+    ComContext ctx( COINIT_APARTMENTTHREADED );
     d->inversion = inversion;
     return d->module->SetInversion( d->inversion );
 }
 
 int dvb_tune (dvb_device_t *d)
 {
+    ComContext ctx( COINIT_APARTMENTTHREADED );
     return d->module->SubmitTuneRequest ();
 }
 
@@ -213,12 +219,14 @@ bool dvb_set_ca_pmt (dvb_device_t *, en50221_capmt_info_t *)
 int dvb_set_dvbc (dvb_device_t *d, uint32_t freq, const char *mod,
                   uint32_t srate, uint32_t /*fec*/)
 {
+    ComContext ctx( COINIT_APARTMENTTHREADED );
     return d->module->SetDVBC (freq / 1000, mod, srate);
 }
 
 /* DVB-S */
 int dvb_set_dvbs (dvb_device_t *d, uint64_t freq, uint32_t srate, uint32_t fec)
 {
+    ComContext ctx( COINIT_APARTMENTTHREADED );
     d->frequency = freq / 1000;
     d->srate = srate;
     d->fec = fec;
@@ -236,6 +244,7 @@ int dvb_set_dvbs2 (dvb_device_t *, uint64_t /*freq*/, const char * /*mod*/,
 int dvb_set_sec (dvb_device_t *d, uint64_t freq, char pol,
                  uint32_t lowf, uint32_t highf, uint32_t switchf)
 {
+    ComContext ctx( COINIT_APARTMENTTHREADED );
     d->frequency = freq / 1000;
     d->pol = pol;
     d->lowf = lowf;
@@ -250,6 +259,7 @@ int dvb_set_dvbt (dvb_device_t *d, uint32_t freq, const char * /*mod*/,
                   uint32_t fec_hp, uint32_t fec_lp, uint32_t bandwidth,
                   int transmission, uint32_t guard, int hierarchy)
 {
+    ComContext ctx( COINIT_APARTMENTTHREADED );
     return d->module->SetDVBT(freq / 1000, fec_hp, fec_lp,
                               bandwidth, transmission, guard, hierarchy);
 }
@@ -259,6 +269,7 @@ int dvb_set_dvbt2 (dvb_device_t *d, uint32_t freq, const char * /*mod*/,
                    uint32_t fec, uint32_t bandwidth, int transmission,
                    uint32_t guard, uint8_t plp)
 {
+    ComContext ctx( COINIT_APARTMENTTHREADED );
     return d->module->SetDVBT2(freq / 1000, fec,
                       bandwidth, transmission, guard, plp);
 }
@@ -287,11 +298,13 @@ int dvb_set_isdbt (dvb_device_t *, uint32_t /*freq*/, uint32_t /*bandwidth*/,
 /* ATSC */
 int dvb_set_atsc (dvb_device_t *d, uint32_t freq, const char * /*mod*/)
 {
+    ComContext ctx( COINIT_APARTMENTTHREADED );
     return d->module->SetATSC(freq / 1000);
 }
 
 int dvb_set_cqam (dvb_device_t *d, uint32_t freq, const char * /*mod*/)
 {
+    ComContext ctx( COINIT_APARTMENTTHREADED );
     return d->module->SetCQAM(freq / 1000);
 }
 
@@ -393,9 +406,6 @@ BDAGraph::BDAGraph( vlc_object_t *p_this ):
     p_sample_grabber = p_mpeg_demux = p_transport_info = NULL;
     p_scanning_tuner = NULL;
     p_grabber = NULL;
-
-    if( FAILED(CoInitializeEx( NULL, COINIT_APARTMENTTHREADED )) )
-        vlc_assert_unreachable();
 }
 
 /*****************************************************************************
@@ -410,7 +420,6 @@ BDAGraph::~BDAGraph()
     p_tuning_space = NULL;
 
     systems = 0;
-    CoUninitialize();
 }
 
 /*****************************************************************************
diff --git a/modules/access/dtv/bdagraph.hpp b/modules/access/dtv/bdagraph.hpp
index fa0e6538ed..df34bdfdc8 100644
--- a/modules/access/dtv/bdagraph.hpp
+++ b/modules/access/dtv/bdagraph.hpp
@@ -36,6 +36,7 @@
 
 #include <comcat.h>
 #include "dtv/bdadefs.h"
+#include <stdexcept>
 
 
 // TBS tuner extension headers
@@ -62,6 +63,18 @@ DWORD KSPROPERTY_BDA_PLPINFO = 22;
 // End of TBS tuner extension headers
 
 
+struct ComContext
+{
+    ComContext( int mode )
+    {
+        if( FAILED( CoInitializeEx( NULL, mode ) ) )
+            throw std::runtime_error( "CoInitializeEx failed" );
+    }
+    ~ComContext()
+    {
+        CoUninitialize();
+    }
+};
 
 class BDAOutput
 {



More information about the vlc-commits mailing list