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

QtNetwork Mac OS X "Memory Leak" ( QSslSocketBackendPrivate::transmit() ?)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 5.6.3
    • 5.6.0, 5.7.0
    • Network: SSL
    • None
    • Mac OS X 10.11.5 (15F34)
      Qt Creator 4.0.0
      Based on Qt 5.6.0 (Clang 7.0 (Apple), 64 bit)
      From revision 605ea627cc
      SecureTransport
    • macOS
    • 158781ff2555fabcb9af6b47c887519ade5aba50

    Description

      I will be using the term "memory leak" when I mean "unnecessary and unacceptably huge growth in memory usage", the memory actually gets released when the request is finished. TL;DR at the bottom.

      In my application I need to setReadBufferSize on a QNetworkReply * and use the readyRead() signal to read data and write it into a file. I'm not reading all the data available, I'm reading it in chunks (sometimes small) and sometimes queue the reads to a later time.

      With HTTPS URLs, it often results in huge memory leaks. I attached a small project where the situation is reproducible and I also attached a screencast of one of the runs (it sometimes, very rarely though, can't be reproduced). The executable simply starts a GET requests with an HTTPS URL and reads only 25 bytes from the QNetworkReply* at a time. I tried different values, but it seems like the lesser the value - the better the chances are to reproduce the issue. (There is a default url hardcoded and an ability to provide the url as a positional argument)

      Here's the screencast of the Xсode Instruments tool when the attached project is built and run:
      https://drive.google.com/file/d/0B7Mr7aUqMlQ0WjJUQmJZNHBwX00/view?usp=sharing

      So the allocated memory resizes to twice its size from time to time.
      And the "leak", as identified by the Xcode Intstruments, happens somewhere in:
      QSslSocketBackendPrivate::transmit()
      I also attached a text file "callstack.rtf" with the call stack that I copied from Xcode Instruments.

      TL;DR
      Reading from QNetworkReply * in a readyRead()-attached slot often results in huge memory leaks when dealing with HTTPS URLs. (Presumably, when reading in small chunks from QNetworkReply's internal buffer). Xcode Instruments blames QSslSocketBackendPrivate::transmit()

      If you are going to dig into this, please let me know of a temporary workaround if there is one.

      Attachments

        1. callstack.rtf
          18 kB
          Artem Pronskikh
        2. qnetworkreply-https-read.zip
          6 kB
          Artem Pronskikh

        Issue Links

          Activity

            People

              tpochep Timur Pocheptsov
              artemskikh_work Artem Pronskikh
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: