程式需要用到MySQL來進行持久化,代碼在windows測試通過,但在Linux調試時,産生下面的異常:
Thread 9 "NodesManagerd" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff2b08700 (LWP 9389)]
0x00007ffff77f1dc0 in ?? () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20
通過調試,最後定位到是執行mysql_query産生的問題:
265 assert(_handle != nullptr && sql != nullptr);
(gdb) n
266 if (mysql_query(_handle, sql) != 0)
(gdb) n
Thread 9 "NodesManagerd" received signal SIGSEGV, Segmentation fault.
0x00007ffff77f1dc0 in ?? () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20
_handle不為空,sql(SELECT NodeId, LastKeepAlive, Status FROM NodeStatus;)正常。起初不明白為什麼出現這樣的問題,sql沒有問題,問題隻能出現在_handle。檢視_handle初始化方式如下:
_handle = mysql_init(&_mysql);
将初始化方式改為:
_handle = mysql_init(nullptr);
問題解決。但不知為什麼第一種方式在windows上正常運作,在linux卻當掉。