List:MySQL++« Previous MessageNext Message »
From:Björn Persson Date:August 16 2005 1:52pm
Subject:Crashes and memory corruption
View as plain text  
Hi everybody!

I'm having big problems with crashes in programs that use MySQL++. They seem 
to crash somewhere in Query::store(), but not on every call. It can be on the 
second call to store(), or the fifth. Some programs don't crash at all, and 
those that do seem to crash in the same place every time as long as the 
environment doesn't change too much.

The crashes started happening when I upgraded from Fedora Core 3 to Fedora 
Core 4, so there are new versions of just about everything in the system. I 
also run these programs on Suse 9.2, and so far they don't crash there. One 
might then think the bug is in GCC or some system library in Fedora 4, but no 
other programs are crashing, only these that use MySQL++. I'd rather think 
it's some change that has exposed a previously hidden bug.

I have tried MySQL++ 1.7.35, 1.7.40 and 2.0.0-rc1. (I compile MySQL++ 
locally.) I've also tried replacing MySQL 4.1.12 from Fedora with a locally 
compiled MySQL 4.0.25. These changes didn't help. They only caused the 
crashes to happen in other places.

So it seems that either I'm doing something wrong, or it's a bug in MySQL++. I 
thought I had figured out a way I could use the library without causing 
dangling pointers and such, but maybe I was wrong. I don't think I can 
produce a test case that crashes reproducibly, but here's a stripped-down 
example of how I use the library:

I establish a connection and pass the connection object to a function (called 
"worker" here). When this function returns I close the connection:

   Connection con(use_exceptions);
   string     DB_username;

   try {
      DB_username = "ess_user";
      con.real_connect("ess", NULL, DB_username.c_str(), "password");
      worker(con);
      con.close();
   }
   catch (exception& error) {
      cerr << "Error: " << error.what() << endl;
   }

In this other function, I write queries into Query objects and execute them 
with store(). If I know that the query only returns one line I store the 
first like in a Row object. Otherwise I typically iterate over the result 
with a Result::iterator:

void worker(Connection& con) {
   Query        data_query = con.query();
   Query        product_query = con.query();
   Query        company_query = con.query();
   Result       data_result;
   Result       product_result;
   Result       company_result;
   Row          data;

   data_query << "select company, contact, sum "
                 "from " << table_name
              << " where ID=" << reference;
   data_result = data_query.store();
   if(data_result.num_rows() < 1) {
      throw not_found("Ogiltig referens.");
   }
   data = data_result[0];
   company_ID = string(data.lookup_by_name("company"));
   product_query << "select ID, name from products, product_privileges "
                    "where ID=product and user=" << user.ID;
   product_result = product_query.store();
   for(Result::iterator rowp = product_result.begin();
       rowp != product_result.end();
       rowp++)
   {
      do_stuff_with(string((*rowp)[0]), string((*rowp)[1]));
   }
   company_query << "select name from companies where ID=" << company_ID;
   company_result = company_query.store();
   if(company_result.num_rows() < 1) {
      throw not_found("Obefintligt företag.");
   }

And on one of the calls to store(): bang! Is there anything in this code that 
can cause that?

Is anyone else having this problem? Are there any other users of Fedora 4 on 
this list?

I also sometimes get error printouts from GlibC about corrupted pointers. I'm 
not sure how related they are to the crash problem, as programs sometimes run 
to completion after these printouts. Here are some examples. I have memory 
maps too if anyone wants them.

*** glibc detected *** /home/bjorn/jobb/säljstöd/ess/show_company: corrupted 
double-linked list: 0x084c0190 ***
======= Backtrace: =========
/lib/libc.so.6[0x76e548]
/lib/libc.so.6(__libc_free+0x77)[0x76e95f]
/usr/lib/mysql/libmysqlclient.so.14(my_no_flags_free+0x21)[0x1b4fb2]
/usr/lib/mysql/libmysqlclient.so.14(mysql_free_result+0x72)[0x1d386d]
/usr/local/lib/libmysqlpp.so.4(_ZN7mysqlpp6ResUse5purgeEv+0x28)[0x3167b4]
/usr/local/lib/libmysqlpp.so.4(_ZN7mysqlpp6ResUseD2Ev+0x2e)[0x316342]
/home/bjorn/jobb/säljstöd/ess/show_company(_ZN7mysqlpp6ResultD1Ev+0x21)
[0x8050793]
/home/bjorn/jobb/säljstöd/ess/show_company[0x804f8ec]
/home/bjorn/jobb/säljstöd/ess/show_company[0x805ada5]
/home/bjorn/jobb/säljstöd/ess/show_company(__gxx_personality_v0+0x18e)
[0x804d0d6]
/lib/libc.so.6(__libc_start_main+0xc6)[0x71fde6]
/home/bjorn/jobb/säljstöd/ess/show_company(__gxx_personality_v0+0x91)
[0x804cfd9]

*** glibc detected 
*** /home/bjorn/jobb/säljstöd/ess-X/branches/MySQL++2/show_tender: double 
free or corruption (!prev): 0x09030190 ***
======= Backtrace: =========
/lib/libc.so.6[0x870424]
/lib/libc.so.6(__libc_free+0x77)[0x87095f]
/usr/local/lib/libmysqlpp.so.2(my_no_flags_free+0x16)[0x78bb86]
/usr/local/lib/libmysqlpp.so.2(mysql_close+0x61)[0x789d25]
/home/bjorn/jobb/säljstöd/ess-X/branches/MySQL++2/show_tender[0x8056af9]
/home/bjorn/jobb/säljstöd/ess-X/branches/MySQL++2/show_tender[0x8055ba1]
/home/bjorn/jobb/säljstöd/ess-X/branches/MySQL++2/show_tender(__gxx_personality_v0+0x19e)
[0x804c1be]
/lib/libc.so.6(__libc_start_main+0xc6)[0x821de6]
/home/bjorn/jobb/säljstöd/ess-X/branches/MySQL++2/show_tender(__gxx_personality_v0+0xa1)
[0x804c0c1]

*** glibc detected 
*** /home/bjorn/jobb/säljstöd/ess-X/branches/MySQL++2/enter_event: free(): 
invalid pointer: 0x08411610 ***
======= Backtrace: =========
/lib/libc.so.6[0x92f424]
/lib/libc.so.6(__libc_free+0x77)[0x92f95f]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x7563a9]
/usr/local/lib/libmysqlpp.so.2
(_ZN9__gnu_cxx10__mt_allocIN7mysqlpp15mysql_type_infoENS_20__common_pool_policyINS_6__poolELb1EEEE10deallocateEPS2_j+0x46)
[0x1f3aca]
/usr/local/lib/libmysqlpp.so.2(_ZN7mysqlpp6ResUse5purgeEv+0xd5)[0x1fd745]
/usr/local/lib/libmysqlpp.so.2(_ZN7mysqlpp6ResUseD2Ev+0x43)[0x1fd077]
/home/bjorn/jobb/säljstöd/ess-X/branches/MySQL++2/enter_event(_ZN7mysqlpp6ResultD1Ev+0x3b)
[0x805397f]
/home/bjorn/jobb/säljstöd/ess-X/branches/MySQL++2/enter_event[0x8051eb1]
/home/bjorn/jobb/säljstöd/ess-X/branches/MySQL++2/enter_event[0x805c497]
/home/bjorn/jobb/säljstöd/ess-X/branches/MySQL++2/enter_event(__gxx_personality_v0+0x280)
[0x804c388]
/lib/libc.so.6(__libc_start_main+0xc6)[0x8e0de6]
/home/bjorn/jobb/säljstöd/ess-X/branches/MySQL++2/enter_event(__gxx_personality_v0+0xa1)
[0x804c1a9]

Björn Persson
Thread
Crashes and memory corruptionBjörn Persson16 Aug
  • Re: Crashes and memory corruptionWarren Young16 Aug
    • Re: Crashes and memory corruptionBjörn Persson17 Aug
      • Re: Crashes and memory corruptionWarren Young17 Aug
        • Re: Crashes and memory corruptionBjörn Persson18 Aug
          • Re: Crashes and memory corruptionThomas Werth18 Aug
          • Re: Crashes and memory corruptionWarren Young18 Aug
        • Re: Crashes and memory corruptionBjörn Persson25 Nov
          • Re: Crashes and memory corruptionWarren Young15 Dec
            • Re: Crashes and memory corruptionBjörn Persson15 Dec
Re: Crashes and memory corruptionJan Busch20 Dec
  • Re: Crashes and memory corruptionChris Frey20 Dec
Re: Crashes and memory corruptionJan Busch21 Dec