[vlc-commits] [Git][videolan/vlc][master] qt: prevent potential double COM library uninitialize in mainctx_win32
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Mon Jul 1 12:47:02 UTC 2024
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
1a26d96f by Fatih Uzunoglu at 2024-07-01T12:20:32+00:00
qt: prevent potential double COM library uninitialize in mainctx_win32
- - - - -
2 changed files:
- modules/gui/qt/maininterface/mainctx_win32.cpp
- modules/gui/qt/maininterface/mainctx_win32.hpp
Changes:
=====================================
modules/gui/qt/maininterface/mainctx_win32.cpp
=====================================
@@ -556,7 +556,6 @@ WinTaskbarWidget::~WinTaskbarWidget()
ImageList_Destroy( himl );
if(p_taskbl)
p_taskbl->Release();
- CoUninitialize();
}
Q_GUI_EXPORT HBITMAP qt_pixmapToWinHBITMAP(const QPixmap &p, int hbitmapFormat = 0);
@@ -580,16 +579,22 @@ void WinTaskbarWidget::createTaskBarButtons()
if (!winId)
return;
- HRESULT hr = CoInitializeEx( NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE );
- if( FAILED(hr) )
+ try
+ {
+ m_comHolder = ComHolder();
+ }
+ catch( const std::exception& exception )
+ {
+ msg_Err( p_intf, "%s", exception.what() );
return;
+ }
void *pv;
- hr = CoCreateInstance( CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER,
- IID_ITaskbarList3, &pv);
+ HRESULT hr = CoCreateInstance( CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER,
+ IID_ITaskbarList3, &pv);
if( FAILED(hr) )
{
- CoUninitialize();
+ m_comHolder.reset();
return;
}
@@ -604,7 +609,7 @@ void WinTaskbarWidget::createTaskBarButtons()
{
p_taskbl->Release();
p_taskbl = NULL;
- CoUninitialize();
+ m_comHolder.reset();
return;
}
=====================================
modules/gui/qt/maininterface/mainctx_win32.hpp
=====================================
@@ -28,6 +28,8 @@
#include "interface_window_handler.hpp"
#include <QAbstractNativeEventFilter>
+#include <objbase.h>
+
class WinTaskbarWidget : public QObject, public QAbstractNativeEventFilter
{
Q_OBJECT
@@ -51,6 +53,22 @@ private:
UINT taskbar_wmsg = 0;
QWindow* m_window = nullptr;
+ class ComHolder
+ {
+ public:
+ ComHolder()
+ {
+ if (Q_UNLIKELY(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE))))
+ throw std::runtime_error("CoInitializeEx failed");
+ }
+
+ ~ComHolder()
+ {
+ CoUninitialize();
+ }
+ };
+
+ std::optional<ComHolder> m_comHolder;
};
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/1a26d96f75b9308c3eb67a002cc08ac4fd6db0b9
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/1a26d96f75b9308c3eb67a002cc08ac4fd6db0b9
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list