fix potential mem leak on connection lost

The PostgreSQL driver can change it's connection status
after the first established connection.
In this case, the function "isOpen()" returns false
and the "close()" function would not free all resources.
With this fix, the "close()" function
always frees any allocated resource
independent of the connection status.

Fixes: QTBUG-88984
Pick-to: 6.0 5.15 5.12
Change-Id: I7c9add6a183bf46a8573952ab39f8cb1f728c00c
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
Matthias Möller 2020-12-09 21:39:20 +01:00
parent 94b6bec01f
commit 6e9125608f

View File

@ -1197,7 +1197,6 @@ bool QPSQLDriver::open(const QString &db,
const QString &connOpts) const QString &connOpts)
{ {
Q_D(QPSQLDriver); Q_D(QPSQLDriver);
if (isOpen())
close(); close();
QString connectString; QString connectString;
if (!host.isEmpty()) if (!host.isEmpty())
@ -1241,7 +1240,6 @@ bool QPSQLDriver::open(const QString &db,
void QPSQLDriver::close() void QPSQLDriver::close()
{ {
Q_D(QPSQLDriver); Q_D(QPSQLDriver);
if (isOpen()) {
d->seid.clear(); d->seid.clear();
if (d->sn) { if (d->sn) {
@ -1256,7 +1254,6 @@ void QPSQLDriver::close()
setOpen(false); setOpen(false);
setOpenError(false); setOpenError(false);
} }
}
QSqlResult *QPSQLDriver::createResult() const QSqlResult *QPSQLDriver::createResult() const
{ {