Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
6.8.3
-
None
-
-
All
Description
The QSqlDatabase Destructor calls close which calls driver->close without testing if driver is a nullptr.
QSqlDatabase::~QSqlDatabase()
{
if (!d->ref.deref()) {
close();
delete d;
}
}
void QSqlDatabase::close()
{
d->driver->close();
}
So if your fail to load a driver plugin your always run into a nullptr dereferencation when QSqlDatabase goes out of scope.
The same applies to other functions (e.g. isOpen()) but this is less critical, because I can test if driver is nullptr before calling them. The destructor call is unavoidable. If your fail to load a driver, your run into a SegFault, there is no way to avoid this.
Minimal Example:
int main() { auto db = QSqlDatabase::addDatabase("", ""); } // SegFault