List:MySQL++« Previous MessageNext Message »
From:Graham Reitz Date:November 25 2007 8:13pm
Subject:Query object seg. faults on destruction...(ignore earlier posts please)
View as plain text  
With the code (below) the Query object segmentation faults on its  
destructor call.  Any help would be greatly appreciated.  I am quite  
stuck.  The same code appears to compile and run and a Windows XP  
machine using VS2005.  I am pretty sure it worked on Mac OS X 10.4.x  
(Tiger) but not certain.

kindly,
graham


OS:
Mac OS X 10.5.1 (Leopard)


Linker flags :
-lz /usr/local/mysql/lib/mysql/libmysqlclient_r.a -lmysqlpp


Other notes:
mysql_client was built from scratch, although I get the same error  
with the prebuilt libraries.


Output:
Attempting to connect to the database...connected to the database
Query created: select client_id from clients where client_user_name  
='tacadmin' and client_password ='tacadmin123'
Segmentation fault


Backtrace:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0xfffffffc
0x92b7f6e1 in __gnu_cxx::__exchange_and_add ()
(gdb) backtrace
#0  0x92b7f6e1 in __gnu_cxx::__exchange_and_add ()
#1  0x92b6f070 in std::string::_Rep::_M_dispose ()
#2  0x92b704ab in std::basic_string<char, std::char_traits<char>,  
std::allocator<char> >::~basic_string ()
#3  0x00002ca8 in std::basic_stringbuf<char, std::char_traits<char>,  
std::allocator<char> >::~basic_stringbuf (this=0xbffff794) at iosfwd:71
#4  0x00002d13 in std::basic_stringbuf<char, std::char_traits<char>,  
std::allocator<char> >::~basic_stringbuf (this=0xbffff794) at iosfwd:71
#5  0x00004351 in mysqlpp::Query::~Query (this=0xbffff6f8) at query.h: 
131
#6  0x00001c2f in main (argc=1, argv=0xbffff8d4) at /Users/grahamreitz/ 
Development/mysqlpp_test/main.cpp:54


Code:
#include <iostream>
#include <string>
#include <mysql++.h>

using namespace std;
using namespace mysqlpp;

int main (int argc, char * const argv[])
{
     string database_name = "db_rev_4";
     string ip_address = "x.x.x.x";
     string username = "username";
     string password = "password";
     string error_msg;

     try
     {
         Result client_id_result;

         cout << "Attempting to connect to the database...";
         Connection m_connection(database_name.c_str(),
                                 ip_address.c_str(),
                                 username.c_str(),
                                 password.c_str(),
                                 3306,
                                 false,
                                 15);

         cout << "connected to the database" << endl;

         Query client_id_query = m_connection.query();

         client_id_query <<
             "select client_id from clients where client_user_name ="
             << quote_only << username << " and client_password ="
             << quote_only << password;

         cout << "Query created: ";
         cout << client_id_query.preview() << endl;

         m_connection.close();
     }
     catch (exception &e)
     {
         cout << "exception occurred..." << endl;
         error_msg = e.what();
         cout << error_msg;
     }
     catch (...)
     {
         error_msg = "Unknown exception";
         cout << error_msg << endl;
     }

     return 0;
}


Also if the Query code is commented out the output is as follows.  It  
goes away if I comment out the Result object.

Attempting to connect to the database...connected to the database
mysqlpp_test(7767) malloc: *** error for object 0x18a198: Non-aligned  
pointer being freed
*** set a breakpoint in malloc_error_break to debug


Thread
Query object seg. faults on destruction...(ignore earlier posts please)Graham Reitz25 Nov
  • Re: Query object seg. faults on destruction...Graham Reitz26 Nov
    • Re: Query object seg. faults on destruction...Warren Young26 Nov