8 messages in com.mysql.lists.plusplusRe: bug in Store() in mysql++ for Bor...| From | Sent On | Attachments |
|---|---|---|
| Michael Masson | 26 Jun 2004 14:49 | |
| Michael Masson | 26 Jun 2004 14:53 | |
| bayufa | 29 Jun 2004 02:01 | |
| Mark Scholtens | 29 Jun 2004 03:11 | |
| sinisa | 29 Jun 2004 05:34 | |
| sinisa | 29 Jun 2004 05:45 | |
| bayufa | 29 Jun 2004 19:54 | |
| sinisa | 30 Jun 2004 05:18 |
| Subject: | Re: bug in Store() in mysql++ for Borland![]() |
|---|---|
| From: | sinisa (sin...@beotel.yu) |
| Date: | 06/29/2004 05:45:39 AM |
| List: | com.mysql.lists.plusplus |
bayufa wrote:
Hi All
I think i found a bug or something ! I found memory leak warning ( using CodeGuard for Borland Builder 6 ) after i terminate application . I'm doing this because i found some 'memory corruption' indication in my application . So it can crash randomly .
My code is pretty simple ..
in a thread
while (1) { Result res; Row row;
sql = "SELECT .... "; Query query = con.query();
query << sql.c_str(); query.store();
..... do the rest }
I found some memory leak point to function store() . I read the source code and found that there is actually memory allocation ( for char ) in the function. Im not sure , but i think someone forgot to delete it .
But if i change the code to something like this
sql = "SELECT ... " Query query = con.query(); query.store(sql.c_str());
...
It also work , and does not produce Memory Leak warning . Im just a beginner . So i just inform you guys about the situation ..! Perhaps someone can explain better ..
thanks BayuFA
1.7.9 does not have memory leaks.
the only one found so far, is the following one:
--- result_orig.cc 2002-11-14 03:19:28.000000000 +0100 +++ result.cc 2002-11-14 03:20:16.000000000 +0100 @@ -20,11 +20,11 @@ }
void ResUse::copy(const ResUse& other) { + if (initialized) + purge(); if (!other.mysql_res) { mysql_res=0; _types=0; _names=0; return; } - if (initialized) - purge(); throw_exceptions = other.throw_exceptions; mysql_res = other.mysql_res; _fields = other._fields;
[...]
Result res;
void sql(const char* q) { // dlog << "[ DB ] Query sent: " << q << endl; try { Query query = con->query();
// Use of dynamically allocated and manually cleaned Result // will eliminate memory leak
// if(res) delete res; // res=new Result(); // *res=query.store(q);
// MEMORY LEAK res=query.store(q);
} [...] }
int main(void) { connect(); int i=0; while(true) { sql("SELECT * FROM a");
// comment out this line to eliminate memory leak sql("UPDATE a SET i=i+1"); dlog << '.'; } }
[...]
And the following ones:
Initial code: void ResUse::copy(const ResUse& other) { if (!other.mysql_res) { mysql_res=0; _types=0; _names=0; return; } if (initialized) purge(); .....
Change to
void ResUse::copy(const ResUse &other) { //maybe check for this==other...? // // clear the current copy... if (initialized) { purge(); } //blank result set? if (!other.mysql_res) { mysql_res=0; _types=0; _names=0; return; }
and
void ResUse::copy(const ResUse& other) { - if (!other.mysql_res) { - mysql_res=0; _types=0; _names=0; return; - } if (initialized) + { purge(); + } + if (!other.mysql_res) + { + mysql_res=0; + _types=0; + _names=0; + return; + } throw_exceptions = other.throw_exceptions; mysql_res = other.mysql_res; _fields = other._fields;
To have your code work correct you have to revert a "fix" that you made.
--
Sincerely,
-- For technical support contracts, go to https://order.mysql.com/?ref=msmi __ ___ ___ ____ __ / |/ /_ __/ __/ __ \/ / Mr. Sinisa Milivojevic <sin...@mysql.com> / /|_/ / // /\ \/ /_/ / /__ MySQL AB /_/ /_/\_, /___/\___\_\___/ Full time Developer and Support Coordinator <___/ www.mysql.com Larnaca, Cyprus




