<html><head></head><body><div class="gmail_quote">Le 22 juillet 2017 01:40:05 GMT+08:00, "Hugo Beauzée-Luyssen" <git@videolan.org> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">vlc | branch: master | Hugo Beauzée-Luyssen <hugo@beauzee.fr> | Fri Jul 21 14:29:35 2017 +0200| [440658435dfaa870337ba121557d628ae5825f30] | committer: Hugo Beauzée-Luyssen<br /><br />bdagraph: Do not leak STA<br /><br />Fix #18183<br /><br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"> <a href="http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=440658435dfaa870337ba121557d628ae5825f30">http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=440658435dfaa870337ba121557d628ae5825f30</a><br /></blockquote>---<br /><br /> modules/access/dtv/bdagraph.cpp | 17 +++++++++++++----<br /> modules/access/dtv/bdagraph.hpp | 13 +++++++++++++<br /> 2 files changed, 26 insertions(+), 4 deletions(-)<br /><br />diff --git a/modules/access/dtv/bdagraph.cpp b/modules/access/dtv/bdagraph.cpp<br />index 1fd51a8395..ea36bc9ff9 100644<br />--- a/modules/access/dtv/bdagraph.cpp<br />+++ b/modules/access/dtv/bdagraph.cpp<br />@@ -149,6 +149,7 @@ dvb_device_t *dvb_open (vlc_object_t *obj)<br /> <br /> void dvb_close (dvb_device_t *d)<br /> {<br />+ ComContext ctx( COINIT_APARTMENTTHREADED );<br /> delete d->module;<br /> delete d;<br /> }<br />@@ -174,27 +175,32 @@ bool dvb_get_pid_state (const dvb_device_t *, uint16_t)<br /> <br /> unsigned dvb_enum_systems (dvb_device_t *d)<br /> {<br />+ ComContext ctx( COINIT_APARTMENTTHREADED );<br /> return d->module->EnumSystems( );<br /> }<br /> <br /> float dvb_get_signal_strength (dvb_device_t *d)<br /> {<br />+ ComContext ctx( COINIT_APARTMENTTHREADED );<br /> return d->module->GetSignalStrength( );<br /> }<br /> <br /> float dvb_get_snr (dvb_device_t *d)<br /> {<br />+ ComContext ctx( COINIT_APARTMENTTHREADED );<br /> return d->module->GetSignalNoiseRatio( );<br /> }<br /> <br /> int dvb_set_inversion (dvb_device_t *d, int inversion)<br /> {<br />+ ComContext ctx( COINIT_APARTMENTTHREADED );<br /> d->inversion = inversion;<br /> return d->module->SetInversion( d->inversion );<br /> }<br /> <br /> int dvb_tune (dvb_device_t *d)<br /> {<br />+ ComContext ctx( COINIT_APARTMENTTHREADED );<br /> return d->module->SubmitTuneRequest ();<br /> }<br /> <br />@@ -213,12 +219,14 @@ bool dvb_set_ca_pmt (dvb_device_t *, en50221_capmt_info_t *)<br /> int dvb_set_dvbc (dvb_device_t *d, uint32_t freq, const char *mod,<br /> uint32_t srate, uint32_t /*fec*/)<br /> {<br />+ ComContext ctx( COINIT_APARTMENTTHREADED );<br /> return d->module->SetDVBC (freq / 1000, mod, srate);<br /> }<br /> <br /> /* DVB-S */<br /> int dvb_set_dvbs (dvb_device_t *d, uint64_t freq, uint32_t srate, uint32_t fec)<br /> {<br />+ ComContext ctx( COINIT_APARTMENTTHREADED );<br /> d->frequency = freq / 1000;<br /> d->srate = srate;<br /> d->fec = fec;<br />@@ -236,6 +244,7 @@ int dvb_set_dvbs2 (dvb_device_t *, uint64_t /*freq*/, const char * /*mod*/,<br /> int dvb_set_sec (dvb_device_t *d, uint64_t freq, char pol,<br /> uint32_t lowf, uint32_t highf, uint32_t switchf)<br /> {<br />+ ComContext ctx( COINIT_APARTMENTTHREADED );<br /> d->frequency = freq / 1000;<br /> d->pol = pol;<br /> d->lowf = lowf;<br />@@ -250,6 +259,7 @@ int dvb_set_dvbt (dvb_device_t *d, uint32_t freq, const char * /*mod*/,<br /> uint32_t fec_hp, uint32_t fec_lp, uint32_t bandwidth,<br /> int transmission, uint32_t guard, int hierarchy)<br /> {<br />+ ComContext ctx( COINIT_APARTMENTTHREADED );<br /> return d->module->SetDVBT(freq / 1000, fec_hp, fec_lp,<br /> bandwidth, transmission, guard, hierarchy);<br /> }<br />@@ -259,6 +269,7 @@ int dvb_set_dvbt2 (dvb_device_t *d, uint32_t freq, const char * /*mod*/,<br /> uint32_t fec, uint32_t bandwidth, int transmission,<br /> uint32_t guard, uint8_t plp)<br /> {<br />+ ComContext ctx( COINIT_APARTMENTTHREADED );<br /> return d->module->SetDVBT2(freq / 1000, fec,<br /> bandwidth, transmission, guard, plp);<br /> }<br />@@ -287,11 +298,13 @@ int dvb_set_isdbt (dvb_device_t *, uint32_t /*freq*/, uint32_t /*bandwidth*/,<br /> /* ATSC */<br /> int dvb_set_atsc (dvb_device_t *d, uint32_t freq, const char * /*mod*/)<br /> {<br />+ ComContext ctx( COINIT_APARTMENTTHREADED );<br /> return d->module->SetATSC(freq / 1000);<br /> }<br /> <br /> int dvb_set_cqam (dvb_device_t *d, uint32_t freq, const char * /*mod*/)<br /> {<br />+ ComContext ctx( COINIT_APARTMENTTHREADED );<br /> return d->module->SetCQAM(freq / 1000);<br /> }<br /> <br />@@ -393,9 +406,6 @@ BDAGraph::BDAGraph( vlc_object_t *p_this ):<br /> p_sample_grabber = p_mpeg_demux = p_transport_info = NULL;<br /> p_scanning_tuner = NULL;<br /> p_grabber = NULL;<br />-<br />- if( FAILED(CoInitializeEx( NULL, COINIT_APARTMENTTHREADED )) )<br />- vlc_assert_unreachable();<br /> }<br /> <br /> /*****************************************************************************<br />@@ -410,7 +420,6 @@ BDAGraph::~BDAGraph()<br /> p_tuning_space = NULL;<br /> <br /> systems = 0;<br />- CoUninitialize();<br /> }<br /> <br /> /*****************************************************************************<br />diff --git a/modules/access/dtv/bdagraph.hpp b/modules/access/dtv/bdagraph.hpp<br />index fa0e6538ed..df34bdfdc8 100644<br />--- a/modules/access/dtv/bdagraph.hpp<br />+++ b/modules/access/dtv/bdagraph.hpp<br />@@ -36,6 +36,7 @@<br /> <br /> #include <comcat.h><br /> #include "dtv/bdadefs.h"<br />+#include <stdexcept><br /> <br /> <br /> // TBS tuner extension headers<br />@@ -62,6 +63,18 @@ DWORD KSPROPERTY_BDA_PLPINFO = 22;<br /> // End of TBS tuner extension headers<br /> <br /> <br />+struct ComContext<br />+{<br />+ ComContext( int mode )<br />+ {<br />+ if( FAILED( CoInitializeEx( NULL, mode ) ) )<br />+ throw std::runtime_error( "CoInitializeEx failed" );<br />+ }<br />+ ~ComContext()<br />+ {<br />+ CoUninitialize();<br />+ }<br />+};<br /> <br /> class BDAOutput<br /> {<br /><br /><hr /><br />vlc-commits mailing list<br />vlc-commits@videolan.org<br /><a href="https://mailman.videolan.org/listinfo/vlc-commits">https://mailman.videolan.org/listinfo/vlc-commits</a><br /></pre></blockquote></div><br clear="all">By my reading of COM docs, this is invalid. COM objects cannot outlive their appartment. And the STA is *not* shared between threads...<br>
-- <br>
Rémi Denis-Courmont<br>
Typed on an inconvenient virtual keyboard</body></html>