Commits

Adam Pritchard committed c4b0825

Fixed memory leak: Successfully validated certs weren't being freed

Comments (0)

Files changed (1)

Client/psiclient/httpsrequest.cpp

     }
 
     HTTPSRequest* httpRequest = (HTTPSRequest*)dwContext;
-    CERT_CONTEXT *pCert = {0};
     DWORD dwStatusCode;
     DWORD dwLen;
     LPVOID pBuffer = NULL;
 
         // Validate server certificate (before requesting)
 
+        CERT_CONTEXT* pCert = NULL;
         dwLen = sizeof(pCert);
         if (!WinHttpQueryOption(
                     hRequest,
             return;
         }
 
-        if (!httpRequest->ValidateServerCert((PCCERT_CONTEXT)pCert))
+        bool valid = httpRequest->ValidateServerCert((PCCERT_CONTEXT)pCert);
+        CertFreeCertificateContext(pCert);
+
+        if (!valid)
         {
-            CertFreeCertificateContext(pCert);
             my_print(httpRequest->m_silentMode, _T("ValidateServerCert failed"));
             // Close request handle immediately to prevent sending of data
             WinHttpCloseHandle(hRequest);