mysqlpp :: Query :: store()上的MySQL ++ malloc_error_break

时间:2013-05-08 01:34:31

标签: c++ mysql dll malloc mysqlpp

扣上这个。

奇怪的是,我无法在网上找到任何关于此类错误的内容,但这让我感到疯狂。希望你们能解释一下这个问题。

我正在使用MySQL ++从表中获取一些基本数据。它连接到数据库很好,查询似乎工作,但运行mysql :: Query :: store()导致malloc错误。

mysqlpp::Connection conn(false);
if(conn.connect("demo", "127.0.0.1", "root", "")) // works
{
    std::string sql = "SELECT * FROM `items`";
    mysqlpp::Query query = conn.query(sql); // works
    mysqlpp::StoreQueryResult res = query.store(); // fails
    if(res)
    {
        mysqlpp::StoreQueryResult::const_iterator it;
        for(it = res.begin(); it != res.end(); ++it) 
        {
            mysqlpp::Row row = *it;

            // Do some things
        }
    }
    else
    {
        std::cerr<<"Failed to get item list: "<<query.error()<<std::endl;
        return false;
    }
}
else
{
    std::cerr<<"DB connection failed: "<<conn.error()<<std::endl;
    return false;
}

gdb backtrace给了我

(gdb) backtrace
#0  0x00007fff841ed499 in malloc_error_break ()
#1  0x00007fff84117183 in free ()
#2  0x000000010029d66c in mysqlpp::Field::~Field ()
#3  0x0000000100493e4d in mysqlpp::ResultBase::ResultBase (this=0x1004805c8, res=0x100480660, dbd=0x100480660, te=122) at result.cpp:40
#4  0x0000000100494690 in mysqlpp::StoreQueryResult::StoreQueryResult (this=0x100480730, res=0x100303e30, dbd=0x100802600) at result.cpp:103
#5  0x0000000100491242 in mysqlpp::Query::store (this=0x3, str=0x100303da0 "SELECT * FROM `items`", len=4298128944) at query.cpp:534
#6  0x00000001004916dc in mysqlpp::Query::store (this=0x3, s=@0x100480848) at query.cpp:508
#7  0x00000001004917c3 in mysqlpp::Query::store (this=0x3) at query.cpp:483
#8  0x0000000100297464 in Load ()
....

Load()是正在运行的函数。

IF 我做了两次查询(我是出于好奇而做的),

mysqlpp::Query query = conn.query(sql);
query = conn.query(sql);
mysqlpp::StoreQueryResult res = query.store();

我没有收到malloc错误,但我收到了SQL错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT * FROM `items`' at line 1

我的g ++版本是

g++ (MacPorts gcc47 4.7.3_0) 4.7.3

有什么想法吗?我之前使用过MySQL ++,但我从来没有遇到任何问题。

此外,此Load()序列恰好位于动态链接库中。(我有一个加载/卸载系统。)如果我注释掉MySQL部分,编译并加载库, 一切都好。如果我然后取消注释该部分,重新​​编译,并重新加载库(主程序仍在运行),查询运行成功!的 WTF

任何帮助都会令人难以置信。谢谢!

1 个答案:

答案 0 :(得分:0)

同样的问题。我的解决方案,检查是否行:

mysqlpp::StoreQueryResult res = query.store(); // fails
if(res.num_rows()){
...
}