diff options
author | Bill King <bill.king@nokia.com> | 2009-04-07 23:53:53 (GMT) |
---|---|---|
committer | Bill King <bill.king@nokia.com> | 2009-04-07 23:53:53 (GMT) |
commit | 06c19716bd9c5974743775de7aa702271b3ab435 (patch) | |
tree | fe71cc27a25803703c1608d52307b79c499c07e3 /src | |
parent | b818bf2d67e4e5f3f3a01eeb0c0de37a4cd33b50 (diff) | |
download | Qt-06c19716bd9c5974743775de7aa702271b3ab435.zip Qt-06c19716bd9c5974743775de7aa702271b3ab435.tar.gz Qt-06c19716bd9c5974743775de7aa702271b3ab435.tar.bz2 |
Fixes: Memory leak in DB2 driver
Looks like they were using the old QPtrVector in qt3, and didn't quite
handle the porting correctly.
Reviewed-by: Lincoln Ramsay
Diffstat (limited to 'src')
-rw-r--r-- | src/sql/drivers/db2/qsql_db2.cpp | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/sql/drivers/db2/qsql_db2.cpp b/src/sql/drivers/db2/qsql_db2.cpp index 69383f7..a6be435 100644 --- a/src/sql/drivers/db2/qsql_db2.cpp +++ b/src/sql/drivers/db2/qsql_db2.cpp @@ -87,8 +87,19 @@ public: {} ~QDB2ResultPrivate() { - for (int i = 0; i < valueCache.count(); ++i) + emptyValueCache(); + } + void clearValueCache() + { + for (int i = 0; i < valueCache.count(); ++i) { delete valueCache[i]; + valueCache[i] = NULL; + } + } + void emptyValueCache() + { + clearValueCache(); + valueCache.clear(); } const QDB2DriverPrivate* dp; @@ -544,7 +555,7 @@ bool QDB2Result::reset (const QString& query) SQLRETURN r; d->recInf.clear(); - d->valueCache.clear(); + d->emptyValueCache(); if (!qMakeStatement(d, isForwardOnly())) return false; @@ -567,7 +578,7 @@ bool QDB2Result::reset (const QString& query) } else { setSelect(false); } - d->valueCache.resize(count); + d->valueCache.resize(count, NULL); setActive(true); return true; } @@ -579,7 +590,7 @@ bool QDB2Result::prepare(const QString& query) SQLRETURN r; d->recInf.clear(); - d->valueCache.clear(); + d->emptyValueCache(); if (!qMakeStatement(d, isForwardOnly())) return false; @@ -607,7 +618,7 @@ bool QDB2Result::exec() SQLRETURN r; d->recInf.clear(); - d->valueCache.clear(); + d->emptyValueCache(); if (!qMakeStatement(d, isForwardOnly(), false)) return false; @@ -810,7 +821,7 @@ bool QDB2Result::exec() setSelect(false); } setActive(true); - d->valueCache.resize(count); + d->valueCache.resize(count, NULL); //get out parameters if (!hasOutValues()) @@ -858,7 +869,7 @@ bool QDB2Result::fetch(int i) return false; if (i == at()) return true; - d->valueCache.fill(0); + d->clearValueCache(); int actualIdx = i + 1; if (actualIdx <= 0) { setAt(QSql::BeforeFirstRow); @@ -887,7 +898,7 @@ bool QDB2Result::fetch(int i) bool QDB2Result::fetchNext() { SQLRETURN r; - d->valueCache.fill(0); + d->clearValueCache(); r = SQLFetchScroll(d->hStmt, SQL_FETCH_NEXT, 0); @@ -907,7 +918,7 @@ bool QDB2Result::fetchFirst() return false; if (isForwardOnly()) return fetchNext(); - d->valueCache.fill(0); + d->clearValueCache(); SQLRETURN r; r = SQLFetchScroll(d->hStmt, SQL_FETCH_FIRST, @@ -923,7 +934,7 @@ bool QDB2Result::fetchFirst() bool QDB2Result::fetchLast() { - d->valueCache.fill(0); + d->clearValueCache(); int i = at(); if (i == QSql::AfterLastRow) { @@ -1101,7 +1112,7 @@ bool QDB2Result::nextResult() setActive(false); setAt(QSql::BeforeFirstRow); d->recInf.clear(); - d->valueCache.clear(); + d->emptyValueCache(); setSelect(false); SQLRETURN r = SQLMoreResults(d->hStmt); @@ -1119,7 +1130,7 @@ bool QDB2Result::nextResult() for (int i = 0; i < fieldCount; ++i) d->recInf.append(qMakeFieldInfo(d, i)); - d->valueCache.resize(fieldCount); + d->valueCache.resize(fieldCount, NULL); setActive(true); return true; |