Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-136117

SegFault in ~QSqlDatabase()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 6.8.3
    • SQL Support
    • None
    • All
    • 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

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            chehrlic Christian Ehrlicher
            bebuch Benjamin Buch
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes