Details
Description
As seen on buildbot http://buildbot.askmonty.org/buildbot/builders/winx64-debug/builds/11784/steps/test/logs/stdio
The reason for the crash is that THD destructor calls Statement_map destructor, which tries to access an already freed mutex LOCK_prepared_stmt_count.
All mutexes are freed when thread_count goes to 0, which happens when unlink_thd() is called for the last THD. Yet, THD destructor is called later, and thus can potentially access a freed mutex.