Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
Subject: mysql openssl Question
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
Update one field with more fields from another table
Subject: Getting Identity after INSERT
ERROR 2002: Can 't connect to local MySQL server through socket
mysql test 4 1 fails with the gis test
Subject: MySQL Cluster Software
Downgrade Mysql from 4 to 3 23
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Can 't access mysql after kernel upgrade
Executing MySQL Commands From Within C Program
Comparing and writing out BLOBS
Subject: Re: Preventing Duplicate Entries
FULLTEXT query format question
Strange behavior, Table Level Permission
Does the binary log enabling affect the MySQL performances?
mysql:it 's a db not a dbms how it 's possible?!
mysql have same function mthod as Oracle decode()
 
Query object seg. faults on destruction...(ignore earlier posts please)

Query object seg. faults on destruction...(ignore earlier posts please)

2007-11-25       - By Graham Reitz

 Back
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