ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
The line that generates this error is trying to open a connection to mysql on the localhost. This connection has been successfully opened before; in fact, this is the second time through the loop, and the first execution of the loop executed flawlessly.
This exact error occurs every time there is a second iteration of the loop. I double-checked to make sure that the connection is closed before it is reopened. Here is output from gdb:
Code:
2018 if( !mysql_real_connect( &conn_temp, server, mysqlUser, mysqlPass, mysqlDB, 0, NULL, 0 )) {
(gdb)
Program received signal SIGSEGV, Segmentation fault.
0x00d21301 in malloc_consolidate () from /lib/tls/libc.so.6
(gdb) backtrace
#0 0x00d21301 in malloc_consolidate () from /lib/tls/libc.so.6
#1 0x00d20b29 in _int_malloc () from /lib/tls/libc.so.6
#2 0x00d1fecd in malloc () from /lib/tls/libc.so.6
#3 0x00eceb8a in my_malloc () from /usr/lib/libmysqlclient.so.12
#4 0x00ee0055 in my_net_init () from /usr/lib/libmysqlclient.so.12
#5 0x00ecb4db in mysql_real_connect () from /usr/lib/libmysqlclient.so.12
#6 0x0804e8e2 in scan (report=1) at ipman.c:2018
#7 0x08049cc9 in main (argc=2, argv=0xbfffc054) at ipman.c:292
(gdb)
I don't expect anyone to be able to solve this, but if you could throw any ideas at me as to what kind of problem to look for on my part, what kind of stupidity would cause malloc_consolidate() to segfault, that would be much appreciated.
Check your loop. If it works the first time, it's likely you forget to "undo" something you did the first time through the loop. I don't use mysql, but my first guess is to make sure that you close the existing mysql connection before you try to connect to it again (using the same data structures, etc.). Usually there are data structures the library needs to keep track of how things are working. The open/connect functions expect those data structures to be initialized to know values, and that's usually what the close/disconnect functions do: they free any used memory and re-initialize the data structure.
That kind of problem has caused me grief before. It may not be the answer to your problem, but it's worth investigating.
Thanks for the reply. You are right on target with your observation. A mysql session starts with mysql_init( &context ), where context is a MYSQL structure that holds all the info about the session. The connection is made to the server with mysql_real_connect( ) and passing such things as a reference to the MYSQL structure, user name, server, etc. The MYSQL structure is wiped and previous connections made with the structure are closed with mysql_close( &context ).
I believe that I have closed everything before trying to reopen it. If you would be willing to check the problem loop, I have posted it at http://zaichik.org/loop.txt (if it's not kosher to post it in links, let me know and I will post it here).
In my test case, all occurences of target_mac[ ] are empty strings, and ip_is_bound() will return 0.
If you have the time, I would really appreciate a second pair of eyes on this (or third, fourth, fifth)...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.