下面的这段代码在windows下运行很正常,在linux就崩溃。请先看代码:
用的mysql-5.6.11 embedded版本。
C/C++ code
const uint16 OPTION_SIZE = 6;
char *gSetup[OPTION_SIZE] = {NULL};
int32 gOptions = sizeof(gSetup)/sizeof(char *);
char *gOptionsGroups[] = {
"embedded",
"server",
"ower_prog",
(char*)NULL
};
/// ......
/* 定义功能名称,该值不出理 */
gSetup[0] = (char*)malloc(strlen("ower_prog") + 1);
strcpy(gSetup[0], "ower_prog");
/* 配置文件的路径 */
#ifdef WIN32
gSetup[1] = (char*)malloc(strlen(szPath) + strlen("--defaults-file=") + strlen("\\my.cnf") + 1);
sprintf(gSetup[1], "%s%s%s", "--defaults-file=", szPath, "\\my.cnf");
/* 错误信息语言包路径 */
gSetup[3] = (char*)malloc(strlen(szPath) + strlen("--language=") + strlen("\\english") + 1);
sprintf(gSetup[3], "%s%s%s", "--language=", szPath, "\\english");
#else
gSetup[1] = (char*)malloc(strlen(szPath) + strlen("--defaults-file=") + strlen("/my.cnf") + 1);
sprintf(gSetup[1], "%s%s%s", "--defaults-file=", szPath, "/my.cnf");
/* 错误信息语言包路径 */
gSetup[3] = (char*)malloc(strlen(szPath) + strlen("--language=") + strlen("/english") + 1);
sprintf(gSetup[3], "%s%s%s", "--language=", szPath, "/english");
#endif
/* DB的路径 */
gSetup[2] = (char*)malloc(strlen(szPath) + strlen("--datadir=") + 1);
sprintf(gSetup[2], "%s%s", "--datadir=", szPath);
/* 取消授权 */
gSetup[4] = (char*)malloc(strlen("--skip-grant-tables") + 1);
strcpy(gSetup[4], "--skip-grant-tables");
gSetup[5] = (char*)malloc(strlen("--skip-innodb") + 1);
strcpy(gSetup[5], "--skip-innodb");
int32 iRet = mysql_library_init(gOptions, gSetup, gOptionsGroups); /// 这里崩溃的
下面是gdb下的coredump文件分析到的堆栈信息
C/C++ code
#4 <signal handler called>
#5 0x013ad599 in init_one_value (option=0x8fd8aa0, variable=0x1, value=8388608) at /root/mysql-5.6.11/mysys_ssl/my_getopt.cc:1219
#6 0x013ae689 in init_variables (argc=0x1d20420, argv=0x1d20424, longopts=0x8fd7078, get_one_option=0x1275660 <mysqld_get_one_option(int, my_option const*, char*)>, command_list=0x0)
at /root/mysql-5.6.11/mysys_ssl/my_getopt.cc:1322
#7 my_handle_options (argc=0x1d20420, argv=0x1d20424, longopts=0x8fd7078, get_one_option=0x1275660 <mysqld_get_one_option(int, my_option const*, char*)>, command_list=0x0)
at /root/mysql-5.6.11/mysys_ssl/my_getopt.cc:203
#8 0x013af5ba in handle_options (argc=0x1d20420, argv=0x1d20424, longopts=0x8fd7078, get_one_option=0x1275660 <mysqld_get_one_option(int, my_option const*, char*)>)
at /root/mysql-5.6.11/mysys_ssl/my_getopt.cc:114
#9 0x01278dae in get_options (argv_ptr=0xd27424, argc_ptr=0xd27420) at /root/mysql-5.6.11/libmysqld/../sql/mysqld.cc:8643
#10 0x0127a311 in init_common_variables () at /root/mysql-5.6.11/libmysqld/../sql/mysqld.cc:3757
#11 0x0127bb0a in init_embedded_server (argc=8, argv=0x8fcbcf0, groups=0x1c44ec4) at /root/mysql-5.6.11/libmysqld/lib_sql.cc:571
#12 0x01272e06 in mysql_server_init (argc=7, argv=0x1d1d4b4, groups=0x1c44ec4) at /root/mysql-5.6.11/libmysql/libmysql.c:170
我初步分析应该是0x013ad599 in init_one_value (option=0x8fd8aa0, variable=0x1,) 不知为何variable本是指针,结果值为1了!
我对这块不熟悉,不知道有人了解不?谢谢。