Bug #31868 mysql_server_init crash when language path is not correctly set
Submitted: 26 Oct 2007 6:27 Modified: 14 Jan 2008 20:29
Reporter: Zhenxing He Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Embedded Library ( libmysqld ) Severity:S3 (Non-critical)
Version:5.1 OS:Windows
Assigned to: Alexey Botchkov CPU Architecture:Any
Tags: crash, embedded, libmysqld

[26 Oct 2007 6:27] Zhenxing He
Description:
When the language option is not set correctly, program that call mysql_server_init will crash on Windows,  but it won't crash on Linux.

The call stack is like the following when crashed:
pthread_lock_mutex
release_ddl_log
end_embedded_server
mysql_server_end
init_embedded_server
mysql_server_init
main

It seems the unitialized LOCK_gdl mutex that caused the crash.

How to repeat:
Write a simple program that calls mysql_library_init or mysql_sever_init at the start, set language option to somewhere not exists an errmsg.sys,  when execute the program, it will crash on Windows

Suggested fix:
The crash is seemly caused by the uninitialized LOCK_gdl mutex,  which is initialized at the end of init_embedded_server, so move the initialization of LOCK_gdl to init_thread_environment would solve this problem.
[26 Oct 2007 6:54] Valeriy Kravchuk
Thank you for a problem report. Please, specify the exact version, 5.1.x, you had used, and send a sample code that demonstrates the problem.
[26 Oct 2007 7:01] Zhenxing He
I have tested 5.1.22-rc and 5.1.23-beta, the following is the test program I used.

------------------- test.c ------------------------------------
#include <my_global.h>
#include <mysql.h>

MYSQL *mysql;			/* the embedded sever class */
MYSQL_RES *results;		/* store results from qeuries */
MYSQL_ROW record;		/* a single row in a result set */

/*
  These variables set the location of the ini file and data stores.
*/
static char *server_options[] = {"mysql_test",
				 "--defaults-file=my.cnf"};
int num_elements=sizeof(server_options) / sizeof(char *);
static char *server_groups[] = {"libmysqld_server", "libmysqld_client"};

int main(void)
{
  /*
    This section initializes the server and sets server options.
   */
  if (mysql_library_init(num_elements,
			server_options,
			server_groups)) {
    fprintf(stderr, "Could not initialize MySQL library\n");
    exit(1);
  }
  mysql_library_end();
}
---------------------- test.c --------------------------------
[28 Oct 2007 19:05] MySQL Verification Team
Thank you for the bug report.
[9 Nov 2007 7:52] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/37408

ChangeSet@1.2625, 2007-11-09 11:47:51+04:00, holyfoot@mysql.com +2 -0
  Bug #31868 mysql_server_init crash when language path is not correctly set.
  
  When mysql_server_init() interrupts on some error (wrong errmsg file
  for example) in the middle of it's execution, it doesn't call
  execute_ddl_log_recovery() so LOCK_gdl mutex isn't init-ed.
  In this case we shouldn't call release_ddl_log during cleanup
  as it uses that mutex inside.
[13 Nov 2007 9:15] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/37641

ChangeSet@1.2625, 2007-11-13 13:09:59+04:00, holyfoot@mysql.com +4 -0
  Bug #31868 mysql_server_init crash when language path is not correctly set.
  
  When mysql_server_init() interrupts on some error (wrong errmsg file
  for example) in the middle of it's execution, it doesn't call
  execute_ddl_log_recovery() so LOCK_gdl mutex isn't init-ed.
  In this case we shouldn't execute release_ddl_log during cleanup
  as it uses that mutex inside.
[14 Dec 2007 8:16] Bugs System
Pushed into 5.1.23-rc
[14 Dec 2007 8:19] Bugs System
Pushed into 6.0.5-alpha
[14 Jan 2008 20:29] Jon Stephens
Documented bugfix in 5.1.23 and 6.0.5 changelogs as follows:

        When the language option was not set correctly, API programs calling
        mysql_server_init() crashed. This issue was observed only on Windows 
        platforms.