As I rewrite the download sample by using HTTPSClientSession, exception is thrown, wihich also leads to memory leak.
- Code: Select all
int main(int argc, char *argv[])
{
SharedPtr<InvalidCertificateHandler> ptrCert = new ConsoleCertificateHandler(false); // ask the user via console
Context::Ptr ptrContext = new Context(Context::CLIENT_USE, "", "", "rootcert.pem", Context::VERIFY_RELAXED, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
SSLManager::instance().initializeClient(0, ptrCert, ptrContext);
try
{
URI uri(argv[1]);
HTTPSClientSession s(uri.getHost(), uri.getPort());
s.setTimeout(Poco::Timespan(20,0)) ;
//set HTTP request
HTTPRequest req(HTTPRequest::HTTP_GET, uri.getPathAndQuery() );
req.setVersion(HTTPRequest::HTTP_1_1) ;
s.sendRequest(req);
//extract the response
HTTPResponse res;
std::istream& rs = s.receiveResponse(res);
std::string resp ;
StreamCopier::copyToString(rs, resp,10240);
if (res.getStatus() == 200)
{
res.write( std::cout ) ;
std::cout << resp << std::endl ;
}
else
{
std::cout << "error: " << res.getStatus() << " " << res.getReason() << std::endl;
}
}
catch (Exception& exc)
{
std::cerr << exc.displayText() << std::endl;
return 1;
}
return 0;
}
Exception "I/O error: Socket operation attempted on non-socket" will be thrown at the end of the program.
It seems that HTTPSClientSession s is not correctly destructed, which lead to memory leak. (When I loop the
request, the memory leak will become more serious).
Could somebody help me to fix the problem? Thanks in advance.





