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

Memory leak in QPSQLDriver when connection is lost before the connection could be closed

    XMLWordPrintable

Details

    • All
    • dbfd3d2892b453e009360ec73bb0040dd482bf58 (qt/qtbase/6.0) 6e9125608f2c07c6c5f41a7a42ea097d1333e1e3 (qt/qtbase/dev) f9bcef1b17e822cfbceb9c0b6dac23b896195738 (qt/tqtc-qtbase/tqtc/lts-5.15)

    Description

      Hi,
      The QPSQLDriver seems to have a memory leak, when a connection is lost. 

      It is affected, by the QPSQLDriver::close#1244 function. The linked line checks, if a connection is OK and, if so, returns true. But it is possible, that a connection is established and afterwards the connection to the server gets lost.
      PostgreSQL switches it's status from OK to BAD when the connection is lost:

      "Ordinarily, an OK status will remain so until PQfinish, but a communications failure might result in the status changing to CONNECTION_BAD prematurely." - link to doc

      In the case of communication failure, the mentioned line returns false and the Postgresql resources do not get freed via PQfinish.

      The user of this class has no chance to call PQfinish on the handle, except by destroying the SQLDriver before it establishes a new connection.
      If a new connection via the "QPSQLopen" function could be established, the PostgreSQL handle is lost, PQfinish will never be called on this handle and this leads to a memory leak.


      To fix the problem, I would suggest to remove the check, if a connection is open (and also the "isOpen" check in the "open" function before calling "close") to ensure that every resource gets freed and the class is in a valid state after calling "close".

      Every resource already checks, if it can be freed, so there no possible double free.
      I have also a patchfile ready, but unsure about the commit policy here.

      Attachments

        For Gerrit Dashboard: QTBUG-88984
        # Subject Branch Project Status CR V

        Activity

          People

            mabrand Mark Brand
            moeller Matthias Möller
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There is 1 open Gerrit change