I'm using the mysql++ library (v3.1.0) in a C++ project (compiled with GCC 4.8.1) in a linux environment, and have an ssqls object as a class member (session_data) of a class I have made (Session). Everything works fine, until an instance of my class comes to be destroyed, at which point a std::string object appears to try to free some memory it does not have, causing the kernel to step in. Below is part of the stack trace given by GDB after the failure.

#2  0x00c143ea in abort () from /lib/libc.so.6
#3  0x00c529d5 in __libc_message () from /lib/libc.so.6
#4  0x00c58e31 in malloc_printerr () from /lib/libc.so.6
#5  0x00c5b571 in _int_free () from /lib/libc.so.6
#6  0x0810e43f in operator delete(void*) () at ../../../../gcc-4.8.1/libstdc++-v3/libsupc++/del_op.cc:47
#7  0x081518eb in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_M_destroy(std::allocator<char> const&) ()
    at /include/ext/new_allocator.h:110
#8  0x08151930 in std::string::_Rep::_M_dispose ()
    at /include/bits/basic_string.h:249
#9  0x0815199e in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() ()
    at /include/bits/basic_string.h:539
#10 0x080ac492 in session_data::~session_data() ()
    at sql_tables.h:80
#11 0x080ac537 in Session::~Session() ()
    at session.cpp:5

All these destructors appear to be created on-the-fly, in that I cannot set a breakpoint inside them because they don't exist according to GDB. Personally, I doubt it is an error in the code GCC has produced, which leaves me to assume I have "mistreated" the ssqls object in some way. So far my efforts to reproduce the error in a smaller project have failed, but if I do manage it I'll be certain to post that code here. Really I'd like to know if anyone has any idea what goes on inside an ssqls object that may be causing this, in the meantime I'll keep trying to debug the issue.

EDIT with minimal code. session_data is delcared entirely by ssqls macros, which I call like so:

sql_create_7(session_data,      4,7,    sql_varchar,    id,
                    sql_text,   last_ip,
                    sql_text,   last_user_agent,
                    sql_datetime,   expires,
                    sql_text,   account,
                    sql_text,   messages,
                    sql_text,   login_key)

The class Session fills the value of session_data by:

mysqlpp::StoreQueryResult res=query.store();
session=res[0];

(With session_data session being a class member, and query a mysql++ query object, which does have data from the database) From time to time session may have its value changed by the line session=tmp; (where tmp is another session_data object). In all other cases variables within session are used by value, eg in session.account, so I don't think they should cause an issue. Hope this helps people a bit more.

有帮助吗?

解决方案

My psychic debugging skills tell me that your Session object got double deleted, OR that it doesn't properly implement the rule-of-(0, 3, 5) and that one of its members got double-deleted (most likely after being shallow copied or assigned).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top