Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 562272

Summary: mysql_init leads to segment fault
Product: Gentoo Linux Reporter: Wallance <halyx>
Component: Current packagesAssignee: Gentoo Linux bug wranglers <bug-wranglers>
Status: RESOLVED INVALID    
Severity: normal CC: hydrapolic
Priority: Normal    
Version: unspecified   
Hardware: AMD64   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: mysql test program
core dump file for gdb debug
emerge --info

Description Wallance 2015-10-05 04:00:16 UTC
Created attachment 413752 [details]
mysql test program

Hello,I use dev-db/mariadb-10.1.7_rc and glibc-2.21.Whenever I call mysql_init(MYSQL*) in my C Language program.It calls for memset and segment fault.

I saved the core dump and backtrace as following.
gdb ./test core.26412
Core was generated by `./test'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  __memset_sse2 () at ../sysdeps/x86_64/memset.S:78
78              movdqu  %xmm8, (%rdi)
(gdb) backtrace
#0  __memset_sse2 () at ../sysdeps/x86_64/memset.S:78
#1  0x00007f2ce2ebb7d3 in mysql_init (mysql=0x4008b0 <_start>)
    at /usr/src/debug/dev-db/mariadb-10.1.7_rc/mysql/sql-common/client.c:1785
#2  0x00000000004009ba in main () at mysql_test.cpp:10

I can upload my test program too.
Comment 1 Wallance 2015-10-05 04:03:10 UTC
Created attachment 413754 [details]
core dump file for gdb debug
Comment 2 Wallance 2015-10-05 04:04:31 UTC
Created attachment 413758 [details]
emerge --info
Comment 3 Wallance 2015-10-05 04:05:38 UTC
I compiled maraidb with client-lib use flag and others are default.
Comment 4 Wallance 2015-10-05 04:43:58 UTC
Please compile the test program as following:
gcc mysql_test.cpp -o test `mysql_config --cflags` `mysql_config --libs`
Comment 5 Tomáš Mózes 2015-10-05 05:31:05 UTC
Hello, according to the manual:
https://mariadb.com/kb/en/mariadb/mysql_init/

MYSQL * mysql_init(MYSQL * mysql);
mysql - a pointer to MYSQL or NULL. In case of passing a NULL pointer mysql_init() will allocate memory and return a pointer to a MYSQL structure.

In your code:
MYSQL *mysql_conn;
mysql_init(mysql_conn);

It means you are passing a pointer, but it has no allocated memory. Try passing a NULL pointer so it will return a pointer for you that will have the memory allocated.

Maybe go over a tutorial, something like:
http://zetcode.com/db/mysqlc/

Good luck!