[vlc-commits] skins2(Win): fix sporadic crash

Erwan Tulou git at videolan.org
Tue Jan 23 02:34:31 CET 2018


vlc | branch: master | Erwan Tulou <erwan10 at videolan.org> | Tue Jan 23 01:46:30 2018 +0100| [90cb142cb5d58ab0d0917bf54499b585e15675b6] | committer: Erwan Tulou

skins2(Win): fix sporadic crash

Timer messages may be pending and must be explicitely discarded
when calling the destructor of a timer. Otherwise, the callback
function is called after the object is destroyed leading to crash.

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

 modules/gui/skins2/win32/win32_timer.cpp | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/modules/gui/skins2/win32/win32_timer.cpp b/modules/gui/skins2/win32/win32_timer.cpp
index afe1550955..c499348716 100644
--- a/modules/gui/skins2/win32/win32_timer.cpp
+++ b/modules/gui/skins2/win32/win32_timer.cpp
@@ -33,10 +33,7 @@ void CALLBACK CallbackTimer( HWND hwnd, UINT uMsg,
 {
     (void)hwnd; (void)uMsg; (void)dwTime;
     Win32Timer *pTimer = (Win32Timer*)idEvent;
-    if( pTimer != NULL )
-    {
-        pTimer->execute();
-    }
+    pTimer->execute();
 }
 
 
@@ -49,6 +46,15 @@ Win32Timer::Win32Timer( intf_thread_t *pIntf, CmdGeneric &rCmd, HWND hWnd ):
 Win32Timer::~Win32Timer()
 {
     stop();
+
+    // discard possible WM_TIMER messages for this timer
+    // already in the message queue and not yet dispatched
+    MSG msg;
+    while( !PeekMessage( &msg, m_hWnd, WM_TIMER, WM_TIMER, PM_REMOVE ) )
+    {
+        if( (Win32Timer*)msg.wParam != this )
+            PostMessage( m_hWnd, WM_TIMER, msg.wParam, msg.lParam );
+    }
 }
 
 



More information about the vlc-commits mailing list