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");
   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 =;
   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 =;
   for(Result::iterator rowp = product_result.begin();
       rowp != product_result.end();
      do_stuff_with(string((*rowp)[0]), string((*rowp)[1]));
   company_query << "select name from companies where ID=" << company_ID;
   company_result =;
   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: =========

*** glibc detected 
*** /home/bjorn/jobb/säljstöd/ess-X/branches/MySQL++2/show_tender: double 
free or corruption (!prev): 0x09030190 ***
======= Backtrace: =========

*** glibc detected 
*** /home/bjorn/jobb/säljstöd/ess-X/branches/MySQL++2/enter_event: free(): 
invalid pointer: 0x08411610 ***
======= Backtrace: =========

Björn Persson
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