Hi all , here is my code for GET request to a http site, but it keeps taking memory nor releasing it, here is the code:

while(1)
{


    hSession = WinHttpOpen(  L"Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0", 
                             WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
                             WINHTTP_NO_PROXY_NAME, 
                             WINHTTP_NO_PROXY_BYPASS, 0);


    if (hSession)
        hConnect = WinHttpConnect( hSession, L"lalala.com",
                                   INTERNET_DEFAULT_HTTP_PORT, 0);






	      hRequest = WinHttpOpenRequest( hConnect, L"GET", 
                                       L"/", 
                                       L"HTTP/1.1", WINHTTP_NO_REFERER, 
                                       WINHTTP_DEFAULT_ACCEPT_TYPES, 
                                       0);

bResults = WinHttpSendRequest( hRequest, 
                                    L"Content-Type: application/x-www-form-urlencoded",
                                   -1,
                                    WINHTTP_NO_REQUEST_DATA, 0, 
                                       0, 0);

  if (bResults)
        bResults = WinHttpReceiveResponse( hRequest, NULL);



  hRequest = WinHttpOpenRequest( hConnect, L"GET", 
                                       L"/forum/index.php?s=viewforum", 
                                       L"HTTP/1.1", WINHTTP_NO_REFERER, 
                                       WINHTTP_DEFAULT_ACCEPT_TYPES, 
                                       0);

bResults = WinHttpSendRequest( hRequest, 
                                    L"Content-Type: application/x-www-form-urlencoded",
                                   -1,
                                    WINHTTP_NO_REQUEST_DATA, 0, 
                                       0, 0);

  if (bResults)
        bResults = WinHttpReceiveResponse( hRequest, NULL);
  

	   if (bResults)
        do 
        {
          
            dwSize = 0;
            if (!WinHttpQueryDataAvailable( hRequest, &dwSize))
              Sleep(1);

           
            pszOutBuffer = new char[dwSize+1];
            if (!pszOutBuffer)
            {
                   dwSize=0;
            }
            else
            {
              
                ZeroMemory(pszOutBuffer, dwSize+1);

                if (!WinHttpReadData( hRequest, (LPVOID)pszOutBuffer, 
                                      dwSize, &dwDownloaded))
                    Sleep(1);
                else
                lol+=pszOutBuffer;

          
                
                delete [] pszOutBuffer;
            }

        } while (dwSize > 0);


  if (hRequest) WinHttpCloseHandle(hRequest);
    if (hConnect) WinHttpCloseHandle(hConnect);
    if (hSession) WinHttpCloseHandle(hSession);

return 0;

}

I can't figure out whats wrong , I have also checked for memory leak using "crtdbg.h" , but no leaks found , any help will be greatly appreciated.. :)

you have to call WinHttpCloseHandle () within the loop so that it is closed after each call to WinHttpConnect(). MOve lines 86-88 up above line 83.

you have to call WinHttpCloseHandle () within the loop so that it is closed after each call to WinHttpConnect(). MOve lines 86-88 up above line 83.

Worked!!!! WHOHOO :*

Then i guess you should mark this thread solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.