List:MySQL++« Previous MessageNext Message »
From:Graham Reitz Date:November 26 2007 2:35am
Subject:Re: Query object seg. faults on destruction...
View as plain text  
Someone suggested that it may have to do with when the Query object
and Connection object are destroyed.  I updated the code, which I
distilled from some other classes I wrote a few months ago where the
Connection object was still in scope.  The gdb output is also below.

The output is different but it still crashes.  Although, this time the  
crash is on the Row operator =.

Any help would be greatly appreciated.

Updated 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 = "xx.xx.xx.xx";
     string username = "username";
     string password = "password";
     string client_id = "graham";
     string client_pw = "reitz";
     string error_msg;

     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);
     try
     {
         Result client_id_result;

         cout << "connected to the database\n";

         Query client_id_query = m_connection.query();

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

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

         client_id_result = client_id_query.store();

         if (client_id_result)
         {
             cout << "Result received = " << client_id_result.rows()
<< endl;
             Row client_id_row;
             Row::size_type i = 0;
             client_id_row = client_id_result.at(i);
             cout << client_id_row << endl;
         }
     }
     catch (exception &e)
     {
         cout << "exception occurred..." << endl;
         error_msg = e.what();
         cout << error_msg;
     }
     catch (...)
     {
         error_msg = "Unknown exception";
         cout << error_msg << endl;
     }

     m_connection.close();

     return 0;
}

GDB Output:

graham-reitzs-macbook-pro:Debug grahamreitz$ gdb mysqlpp_test
This GDB was configured as "i386-apple-darwin"...Reading symbols for
shared libraries ..... done

(gdb) run
Starting program: /Users/grahamreitz/Development/mysqlpp_test/build/
Debug/mysqlpp_test
Reading symbols for shared libraries ++++... done

Attempting to connect to the database...connected to the database
Query created: select client_id from clients where client_user_name
='graham' and client_password ='reitz'
mysqlpp_test(1583) malloc: *** error for object 0x1946b8: Non-aligned
pointer being freed
*** set a breakpoint in malloc_error_break to debug
Result received = 1
/Developer/SDKs/MacOSX10.5.sdk/usr/include/c++/4.0.0/bits/
stl_algobase.h:382:
     error: function requires a valid iterator range [__first, __last).

Objects involved in the operation:
iterator "__first" @ 0x0xbffff120 {
type = N10__gnu_norm19_Bit_const_iteratorE;
}
iterator "__last" @ 0x0xbffff128 {
type = N10__gnu_norm19_Bit_const_iteratorE;
}

Program received signal SIGABRT, Aborted.
0x9264e47a in __kill ()

(gdb) backtrace
#0  0x9264e47a in __kill ()
#1  0x9264e46d in kill$UNIX2003 ()
#2  0x926c5782 in raise ()
#3  0x926d4d3f in abort ()
#4  0x000082d7 in __gnu_debug::_Error_formatter::_M_error
(this=0xbfffefd0) at /SourceCache/libstdcxx/libstdcxx-16/libstdcxx/
libstdc++-v3/src/debug.cc:504
#5  0x000053f3 in std::copy<__gnu_norm::_Bit_const_iterator,
__gnu_norm::_Bit_iterator> (__first={<__gnu_norm::_Bit_iterator_base>
= {<> = {<No data fields>}, _M_p = 0x400b64, _M_offset = 3221223348},
<No data fields>}, __last={<__gnu_norm::_Bit_iterator_base> = {<> =
{<No data fields>}, _M_p = 0x1, _M_offset = 2413823168}, <No data
fields>}, __result={<__gnu_norm::_Bit_iterator_base> = {<> = {<No data
fields>}, _M_p = 0x1000000, _M_offset = 0}, <No data fields>}) at
stl_algobase.h:382
#6  0x000054ee in __gnu_norm::vector<bool, std::allocator<bool>
> ::operator= (this=0xbffff788, __x=@0xbffff85c) at stl_bvector.h:709
#7  0x00005552 in __gnu_debug_def::vector<bool, std::allocator<bool>
> ::operator= (this=0xbffff788, __x=@0xbffff85c) at debug/vector:100
#8  0x000066cc in mysqlpp::Row::operator= (this=0xbffff760) at row.h:54
#9  0x00001e69 in main (argc=1, argv=0xbffff8d4) at /Users/grahamreitz/
Development/mysqlpp_test/main.cpp:49
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