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

Erwan Tulou git at videolan.org
Tue Jan 23 02:36:24 CET 2018


vlc/vlc-3.0 | branch: master | Erwan Tulou <erwan10 at videolan.org> | Tue Jan 23 01:46:30 2018 +0100| [4b48ad5dc66e00a118395c6db9e88ff11ed724e7] | 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.

(cherry picked from commit 90cb142cb5d58ab0d0917bf54499b585e15675b6)
Signed-off-by: Erwan Tulou <erwan10 at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=4b48ad5dc66e00a118395c6db9e88ff11ed724e7
---

 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