# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1568588536 0 # Node ID 21811c9e2eafbafe8aad333e785ba4cfecc79adb # Parent 218fce0e3b06b4764504cfc8fdd7eae53f6e5b76 OS/2: Fix memory and HAB/HMQ leak when compiled with Watcom C. OS/2 and Win: Fix resource leak when calling dw_thread_end(). diff -r 218fce0e3b06 -r 21811c9e2eaf os2/dw.c --- a/os2/dw.c Sat Sep 07 16:47:45 2019 +0000 +++ b/os2/dw.c Sun Sep 15 23:02:16 2019 +0000 @@ -2,7 +2,7 @@ * Dynamic Windows: * A GTK like implementation of the PM GUI * - * (C) 2000-2017 Brian Smith + * (C) 2000-2019 Brian Smith * (C) 2003-2011 Mark Hessling * (C) 2000 Achim Hasenmueller * (C) 2000 Peter Nielsen @@ -11927,16 +11927,16 @@ * However it is exported so language bindings can call it when * they create threads that require access to Dynamic Windows. */ -void API _dw_init_thread(void) +void **_dw_init_thread2(void) { HAB thishab = WinInitialize(0); HMQ thishmq = WinCreateMsgQueue(thishab, 0); -#ifndef __WATCOMC__ void **threadinfo = (void **)malloc(sizeof(void *) * 2); threadinfo[0] = (void *)thishab; threadinfo[1] = (void *)thishmq; +#ifndef __WATCOMC__ *_threadstore() = (void *)threadinfo; #endif @@ -11944,6 +11944,12 @@ /* Set the codepage to 1208 (UTF-8) */ WinSetCp(thishmq, 1208); #endif + return threadinfo; +} + +void API _dw_init_thread(void) +{ + _dw_init_thread2(); } /* @@ -11952,11 +11958,13 @@ * However it is exported so language bindings can call it when * they exit threads that require access to Dynamic Windows. */ -void API _dw_deinit_thread(void) +void _dw_deinit_thread2(void **threadinfo) { #ifndef __WATCOMC__ - void **threadinfo = (void **)*_threadstore(); - + if(!threadinfo) + threadinfo = (void **)*_threadstore(); +#endif + if(threadinfo) { HAB thishab = (HAB)threadinfo[0]; @@ -11966,7 +11974,11 @@ WinTerminate(thishab); free(threadinfo); } -#endif +} + +void API _dw_deinit_thread(void) +{ + _dw_deinit_thread2(NULL); } /* @@ -11976,15 +11988,14 @@ { void (API_FUNC threadfunc)(void *) = NULL; void **tmp = (void **)data; - - _dw_init_thread(); + void **threadinfo = _dw_init_thread2(); threadfunc = (void (API_FUNC)(void *))tmp[0]; threadfunc(tmp[1]); free(tmp); - _dw_deinit_thread(); + _dw_deinit_thread2(threadinfo); } /* @@ -12016,6 +12027,7 @@ */ void API dw_thread_end(void) { + _dw_deinit_thread(); _endthread(); } diff -r 218fce0e3b06 -r 21811c9e2eaf win/dw.c --- a/win/dw.c Sat Sep 07 16:47:45 2019 +0000 +++ b/win/dw.c Sun Sep 15 23:02:16 2019 +0000 @@ -11870,6 +11870,7 @@ void API dw_thread_end(void) { #if !defined(__CYGWIN__) + _dw_deinit_thread(); _endthread(); #endif }