Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Memory leak in QNetworkProxy (should i post on bugtracker?)

    General and Desktop
    qnetworkreply qnetworkaccessm qnetworkrequest qnetworkpoxy memory leak
    2
    3
    1171
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Vlad_Savelyev
      Vlad_Savelyev last edited by Vlad_Savelyev

      I working on a web-spider application that uses lot of proxies. The problem is the memory leaks are enormouse, up to 100 mb in 5 minutes. I wrote a simple test like this, which runs inside QThread:

      worker::process()
      {
      //here i read the proxies from file first
        QString readAll;
        QFile file("proxies.txt");
        if(!file.open(QIODevice::ReadWrite))
        {
           qDebug() << file.errorString();
           emit finished();
           eturn;
        }
        QTextStream in(&file);
      
            while(!in.atEnd())
            {
      
                readAll = in.readAll();
      
            }
            file.close();
      
         
      //split the proxies by new line to the QStringList
        QStringList lst = readAll.split(QRegExp("(\\r\\n)|(\\n\\r)|\\r|\\n"), QString::SkipEmptyParts);
      
        foreach(QString proxy,lst){
      
              QNetworkRequest request;
              request.setUrl(QUrl("https://google.com/"));
      
              request.setRawHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/2022021 Firefox/46.0");
      
              QStringList parts = proxy.split(":");
              QString s_port = parts[1];
            // here is the thing
              QNetworkProxy webProxy;
                  webProxy.setHostName(parts[0]);
                  webProxy.setPort(s_port.toUShort());
                  webProxy.setType(QNetworkProxy::Socks5Proxy);
      
                 m.setProxy(webProxy);
      
      
                 QNetworkReply * reply = m.get(request);
                 QTimer timer;
                 timer.setSingleShot(true);
      
                 QEventLoop loop;
                 QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
                 QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
                 timer.start(1*1000);
                 loop.exec();
      
                 if(reply->isFinished())
                     reply->abort();
      
                 reply->close();
                 delete reply;
           }
      }
      

      So in this foreach im doing the requests, and see memory goes SUPER crazy, and it never decreases even if i stop the thread. But if i comment out this:

      
       QNetworkProxy webProxy;
             /*     webProxy.setHostName(parts[0]);
                  webProxy.setPort(s_port.toUShort());
                  webProxy.setType(QNetworkProxy::Socks5Proxy);*/
      
                 m.setProxy(webProxy);
      

      So basically no proxy request, i dont see any leakages. All is stable. Is it a possible bug? I don't know if i write post here or report to bugtracker? Also im using a small timeout with QEventLoop here, its just for the sake of example, but in reality, i need to abort the request if the proxy is invalid, otherwise it could hang for hours (maybe even days)

      kshegunov 1 Reply Last reply Reply Quote 0
      • kshegunov
        kshegunov Moderators @Vlad_Savelyev last edited by

        @Vlad_Savelyev
        Hello,
        Could you prepare a minimal working example that reproduces this behavior. I could test on my machine, and you'd probably be asked for it anyway if you report as a bug.

        Kind regards.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply Reply Quote 0
        • Vlad_Savelyev
          Vlad_Savelyev last edited by

          sure i will reply with the project code

          1 Reply Last reply Reply Quote 0
          • First post
            Last post