Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 562272 - mysql_init leads to segment fault
Summary: mysql_init leads to segment fault
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: Gentoo Linux bug wranglers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-05 04:00 UTC by Wallance
Modified: 2015-10-05 05:31 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
mysql test program (mysql_test.cpp,654 bytes, text/x-c++src)
2015-10-05 04:00 UTC, Wallance
Details
core dump file for gdb debug (core.26412.gz,340.43 KB, application/x-gzip)
2015-10-05 04:03 UTC, Wallance
Details
emerge --info (info,5.65 KB, text/plain)
2015-10-05 04:04 UTC, Wallance
Details

Note You need to log in before you can comment on or make changes to this bug.
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!