Bug #62968 embedd server crashs when locking on destoried THR_LOCK_malloc
Submitted: 27 Oct 2011 13:36 Modified: 20 Mar 2012 18:54
Reporter: tommy wang Email Updates:
Status: No Feedback Impact on me:
Category:MySQL Server: Embedded Library ( libmysqld ) Severity:S3 (Non-critical)
Version:5.1.59 OS:Linux (SUSE10)
Assigned to: CPU Architecture:Any
Tags: embedded, lock after destory, mutex

[27 Oct 2011 13:36] tommy wang
mysql basedir: /usr/local/mysql
embedded server binary and configfile directory: /data/dev/embedd
the embedded server will crash when starting it, and output some messages like this:
safe_mutex: Trying to lock unitialized mutex at safemalloc.c, line 522

How to repeat:
let the embedded server's basedir differs from the real mysql basedir and start it.

Suggested fix:
i use gdb to debug this problem, found the reason as follows:
1. the basedir is not correct;
2. so share/mysql/english/errmsg.sys can't be found in init_server_components();
3. call unireg_abort() to release resources, including pthread_mutex_destory(THR_LOCK_malloc);
4. after init_server_components() returns, somewhere in mysql_server_end() tries to lock THR_LOCK_malloc which has been destoried; 
5. crash.

my solution:
modified the source code, just commented this line in mysys/my_thr_init.c:

it works, but it's not a good idea i think, so i write this report to u guys:)

btw, there is no helpful error message output at all in sql/mysqld.cc:4078, it takes me much time to debug it:(
[20 Feb 2012 18:54] Sveta Smirnova
Thank you for the report.

Please provide complete test code demonstrating the problem: I can successfully start libmysqld which uses empty or any valid MySQL datadir.
[21 Mar 2012 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".