1,105,214 Community Members

my c++ programe keep taking memory help..

Member Avatar
kk33
Newbie Poster
13 posts since Sep 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.. :)

Member Avatar
Ancient Dragon
Achieved Level 70
27,573 posts since Aug 2005
Reputation Points: 5,231 [?]
Q&As Helped to Solve: 3,028 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
0
 

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.

Member Avatar
kk33
Newbie Poster
13 posts since Sep 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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 :*

Member Avatar
anirudh33
Light Poster
33 posts since Jan 2011
Reputation Points: -4 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
0
 

Then i guess you should mark this thread solved.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: