Note that there are some explanatory texts on larger screens.

plurals
  1. POSegmentation fault when connecting to MySQL
    text
    copied!<p>I have this code in a big project that makes a connection to a MySQL database, and does not work:</p> <pre><code>boost::shared_ptr&lt;sql::Connection&gt; connection; sql::Driver *driver = get_driver_instance(); assert(driver != 0); std::string server = "servname", user = "pietro", password = "abc"; try { connection.reset(driver-&gt;connect(server, user, password)); assert(connection != 0); if(connection-&gt;isClosed() == false) // &lt;-- segmentation fault { } } </code></pre> <p>I get a segmentation fault where indicated (all parameters are valid).<br> However, this same code works in a test project. </p> <p>Going into the <code>sql::Connection::isClosed()</code> member function with a debugger, I obtain no information about the possible cause; here is where I get: </p> <blockquote> <p>mysql-connector-c++-1.0.5/driver/mysql_connection.cpp - line 430</p> </blockquote> <pre><code>/* {{{ MySQL_Connection::checkClosed() -I- */ void MySQL_Connection::checkClosed() { CPP_ENTER_WL(intern-&gt;logger, "MySQL_Connection::checkClosed"); if (!intern-&gt;is_valid) { throw sql::SQLException("Connection has been closed"); } } </code></pre> <p>This <code>checkClosed()</code> function is successfully executed seven times from <code>connection.reset()</code> just before. The value of the "<code>intern</code>" pointer does not change and is not null at this stage. </p> <p>When I check if the connection is closed, the <code>checkClosed()</code> function is run again. Now the "<code>intern</code>" pointer value is 0x8, a location I cannot access. </p> <p>Here I get a <code>SIGSEGV</code>, segmentation fault.</p> <p>Let me know if you would like the disassembled code...</p> <p><em>Platform:</em><br> MySQL 5.x<br> MySQL Connector/C++ 1.0.5<br> Linux - OpenSuse 11.4 </p> <hr> <p>P.S.: I noticed that all the <code>shared_ptr</code>'s member functions work as expected: </p> <pre><code>connection.get(); // = 0x8fb4a0 connection.use_count(); // = 1 connection.unique(); // = 1 </code></pre> <p>while all the calls done on the pointed object cause the segmentation fault (SIGABRT): </p> <pre><code>connection-&gt;getClientInfo(); connection-&gt;isClosed(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload