bugMySQL++ - Bugs: bug #20992, Connection::Connection(db, server,...

 
 
Show feedback again

You are not allowed to post comments on this tracker with your current authentification level.

bug #20992: Connection::Connection(db, server, user, password, port) constructor issue with DBDriver

Submitted by:  Yury Alekseev <yalekseev>
Submitted on:  Mon 29 Jul 2013 08:26:05 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Priority: 5 - NormalStatus: Fixed
Privacy: PublicAssigned to: None
Open/Closed: Closed

Thu 12 Dec 2013 03:18:10 PM UTC, comment #1:

Fixed in r2760. Will appear in next release.

Warren Young <wyoung>
Project Administrator
Mon 29 Jul 2013 08:26:05 AM UTC, original submission:

The Connection::Connection(db, server,user, password, port) constructor allocates a DBDriver prior to calling connect(). The connect() function can throw, for example, because of incorrect server's ip address. Since the Connection object is not fully constructed at this stage yet, it's destructor (Connection::~Connection()) and the corresponding delete on the DBDriver won't be called. This would result in DBDriver leak.

I would like to emphasize that the DESTRUCTOR (Connection::~Connection()) WON'T BE CALLED in the described scenario.

Here follows a use case that exibits the described issue. After running it for 10 to 15 minutes it's easy to see (e.g. with top -p pid) enormous memory consumption by the application.

<<<
#include <iostream>
#include <mysql++.h>

int main() {
while (true) {
try {
mysqlpp::Connection connection("dbname", "incorrect_host_name", "user", "password");

mysqlpp::Query query = connection.query();

query << "SELECT count(*) FROM ExistingTable";

query.execute();
} catch (const mysqlpp::ConnectionFailed & e) {
}
}

return 0;
}
<<<

A possible fix might be as follows:

<<<
<<<
--- ./lib/connection.cpp.orig 2013-07-23 10:25:52.515757998 +0400
+++ ./lib/connection.cpp 2013-07-23 10:35:20.374887359 +0400
@@ -46,28 +46,42 @@ copacetic_(true)
Connection::Connection(const char* db, const char* server,
const char* user, const char* password, unsigned int port) :
OptionalExceptions(),
driver_(new DBDriver()),
copacetic_(true)
{
- connect(db, server, user, password, port);
+ try {
+ connect(db, server, user, password, port);
+ } catch (...) {
+ delete driver_;
+ throw;
+ }
}
}
<<<

Yury Alekseev <yalekseev>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by wyoung (Posted a comment)
  • -unavailable- added by yalekseev (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 12 Dec 2013 03:18:10 PM UTCwyoungStatusNone=>Fixed
      Open/ClosedOpen=>Closed
    Show feedback again

    Back to the top


    Powered by Savane 3.1-cleanup