Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in H5TS_win32_thread_exit #359

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions src/H5TS.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ typedef struct H5TS_cancel_struct {
/* Global variable definitions */
#ifdef H5_HAVE_WIN_THREADS
H5TS_once_t H5TS_first_init_g;
H5TS_key_t H5TS_errstk_key_g = TLS_OUT_OF_INDEXES;
H5TS_key_t H5TS_funcstk_key_g = TLS_OUT_OF_INDEXES;
H5TS_key_t H5TS_cancel_key_g = TLS_OUT_OF_INDEXES;
#else /* H5_HAVE_WIN_THREADS */
H5TS_once_t H5TS_first_init_g = PTHREAD_ONCE_INIT;
#endif /* H5_HAVE_WIN_THREADS */
H5TS_key_t H5TS_errstk_key_g;
H5TS_key_t H5TS_funcstk_key_g;
H5TS_key_t H5TS_cancel_key_g;
#endif /* H5_HAVE_WIN_THREADS */


/*--------------------------------------------------------------------------
Expand Down Expand Up @@ -422,10 +425,16 @@ H5TS_win32_process_exit(void)
DeleteCriticalSection(&H5_g.init_lock.CriticalSection);

/* Clean up per-process thread local storage */
TlsFree(H5TS_errstk_key_g);
if (H5TS_errstk_key_g != TLS_OUT_OF_INDEXES)
{
TlsFree(H5TS_errstk_key_g);
}

#ifdef H5_HAVE_CODESTACK
TlsFree(H5TS_funcstk_key_g);
if (H5TS_funcstk_key_g != TLS_OUT_OF_INDEXES)
{
TlsFree(H5TS_funcstk_key_g);
}
#endif /* H5_HAVE_CODESTACK */

return;
Expand Down Expand Up @@ -461,14 +470,22 @@ H5TS_win32_thread_exit(void)
*/

/* Clean up per-thread thread local storage */
lpvData = TlsGetValue(H5TS_errstk_key_g);
if(lpvData)
LocalFree((HLOCAL)lpvData);
if (H5TS_errstk_key_g != TLS_OUT_OF_INDEXES)
{
if (lpvData = TlsGetValue(H5TS_errstk_key_g))
{
LocalFree((HLOCAL)lpvData);
}
}

#ifdef H5_HAVE_CODESTACK
lpvData = TlsGetValue(H5TS_funcstk_key_g);
if(lpvData)
LocalFree((HLOCAL)lpvData);
if (H5TS_funcstk_key_g != TLS_OUT_OF_INDEXES)
{
if (lpvData = TlsGetValue(H5TS_funcstk_key_g))
{
LocalFree((HLOCAL)lpvData);
}
}
#endif /* H5_HAVE_CODESTACK */

return ret_value;
Expand Down