mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-18 08:22:37 +01:00
- fixed a potential memory leak in Poco::Net::HTTPClientSession if it is misused
(e.g., sendRequest() is sent two times in a row without an intermediate call to receiveResponse(), or by calling receiveResponse() two times in a row without an intermediate call to sendRequest()) - GH #217 - removed a few unnecessary protected accessor methods from Poco::Net::HTTPClientSession that would provide inappropriate access to internal state
This commit is contained in:
parent
872744fd92
commit
9372096447
@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPClientSession.h
|
||||
//
|
||||
// $Id: //poco/1.4/Net/include/Poco/Net/HTTPClientSession.h#4 $
|
||||
// $Id: //poco/1.4/Net/include/Poco/Net/HTTPClientSession.h#5 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: HTTPClient
|
||||
@ -43,6 +43,7 @@
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/HTTPSession.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
|
||||
@ -234,33 +235,6 @@ protected:
|
||||
/// Returns the prefix prepended to the URI for proxy requests
|
||||
/// (e.g., "http://myhost.com").
|
||||
|
||||
void deleteResponseStream();
|
||||
/// Deletes the response stream and sets it to 0.
|
||||
|
||||
void deleteRequestStream();
|
||||
/// Deletes the request stream and sets it to 0.
|
||||
|
||||
void setResponseStream(std::istream* pRespStream);
|
||||
/// Sets the response stream iff _pResponseStream is 0.
|
||||
|
||||
void setRequestStream(std::ostream* pRequestStream);
|
||||
/// Sets the request stream iff _pRequestStream is 0.
|
||||
|
||||
std::istream* getResponseStream() const;
|
||||
/// Returns the currently set response stream. Can return 0.
|
||||
|
||||
std::ostream* getRequestStream() const;
|
||||
/// Returns the currently set request stream. Can return 0.
|
||||
|
||||
void setReconnect(bool recon);
|
||||
/// Sets _reconnect.
|
||||
|
||||
void setExpectResponseBody(bool expect);
|
||||
/// Sets _expectResponseBody.
|
||||
|
||||
bool getExpectResponseBody() const;
|
||||
/// Returns _expectResponseBody.
|
||||
|
||||
virtual bool mustReconnect() const;
|
||||
/// Checks if we can reuse a persistent connection.
|
||||
|
||||
@ -292,8 +266,8 @@ private:
|
||||
bool _reconnect;
|
||||
bool _mustReconnect;
|
||||
bool _expectResponseBody;
|
||||
std::ostream* _pRequestStream;
|
||||
std::istream* _pResponseStream;
|
||||
Poco::SharedPtr<std::ostream> _pRequestStream;
|
||||
Poco::SharedPtr<std::istream> _pResponseStream;
|
||||
|
||||
HTTPClientSession(const HTTPClientSession&);
|
||||
HTTPClientSession& operator = (const HTTPClientSession&);
|
||||
@ -341,36 +315,6 @@ inline const std::string& HTTPClientSession::getProxyPassword() const
|
||||
}
|
||||
|
||||
|
||||
inline std::istream* HTTPClientSession::getResponseStream() const
|
||||
{
|
||||
return _pResponseStream;
|
||||
}
|
||||
|
||||
|
||||
inline std::ostream* HTTPClientSession::getRequestStream() const
|
||||
{
|
||||
return _pRequestStream;
|
||||
}
|
||||
|
||||
|
||||
inline void HTTPClientSession::setReconnect(bool recon)
|
||||
{
|
||||
_reconnect = recon;
|
||||
}
|
||||
|
||||
|
||||
inline void HTTPClientSession::setExpectResponseBody(bool expect)
|
||||
{
|
||||
_expectResponseBody = expect;
|
||||
}
|
||||
|
||||
|
||||
inline bool HTTPClientSession::getExpectResponseBody() const
|
||||
{
|
||||
return _expectResponseBody;
|
||||
}
|
||||
|
||||
|
||||
inline const Poco::Timespan& HTTPClientSession::getKeepAliveTimeout() const
|
||||
{
|
||||
return _keepAliveTimeout;
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// HTTPClientSession.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Net/src/HTTPClientSession.cpp#8 $
|
||||
// $Id: //poco/1.4/Net/src/HTTPClientSession.cpp#10 $
|
||||
//
|
||||
// Library: Net
|
||||
// Package: HTTPClient
|
||||
@ -63,9 +63,7 @@ HTTPClientSession::HTTPClientSession():
|
||||
_keepAliveTimeout(DEFAULT_KEEP_ALIVE_TIMEOUT, 0),
|
||||
_reconnect(false),
|
||||
_mustReconnect(false),
|
||||
_expectResponseBody(false),
|
||||
_pRequestStream(0),
|
||||
_pResponseStream(0)
|
||||
_expectResponseBody(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -77,9 +75,7 @@ HTTPClientSession::HTTPClientSession(const StreamSocket& socket):
|
||||
_keepAliveTimeout(DEFAULT_KEEP_ALIVE_TIMEOUT, 0),
|
||||
_reconnect(false),
|
||||
_mustReconnect(false),
|
||||
_expectResponseBody(false),
|
||||
_pRequestStream(0),
|
||||
_pResponseStream(0)
|
||||
_expectResponseBody(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -91,9 +87,7 @@ HTTPClientSession::HTTPClientSession(const SocketAddress& address):
|
||||
_keepAliveTimeout(DEFAULT_KEEP_ALIVE_TIMEOUT, 0),
|
||||
_reconnect(false),
|
||||
_mustReconnect(false),
|
||||
_expectResponseBody(false),
|
||||
_pRequestStream(0),
|
||||
_pResponseStream(0)
|
||||
_expectResponseBody(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -105,17 +99,13 @@ HTTPClientSession::HTTPClientSession(const std::string& host, Poco::UInt16 port)
|
||||
_keepAliveTimeout(DEFAULT_KEEP_ALIVE_TIMEOUT, 0),
|
||||
_reconnect(false),
|
||||
_mustReconnect(false),
|
||||
_expectResponseBody(false),
|
||||
_pRequestStream(0),
|
||||
_pResponseStream(0)
|
||||
_expectResponseBody(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPClientSession::~HTTPClientSession()
|
||||
{
|
||||
delete _pRequestStream;
|
||||
delete _pResponseStream;
|
||||
}
|
||||
|
||||
|
||||
@ -193,7 +183,6 @@ void HTTPClientSession::setKeepAliveTimeout(const Poco::Timespan& timeout)
|
||||
|
||||
std::ostream& HTTPClientSession::sendRequest(HTTPRequest& request)
|
||||
{
|
||||
delete _pResponseStream;
|
||||
_pResponseStream = 0;
|
||||
|
||||
bool keepAlive = getKeepAlive();
|
||||
@ -259,7 +248,6 @@ std::ostream& HTTPClientSession::sendRequest(HTTPRequest& request)
|
||||
|
||||
std::istream& HTTPClientSession::receiveResponse(HTTPResponse& response)
|
||||
{
|
||||
delete _pRequestStream;
|
||||
_pRequestStream = 0;
|
||||
|
||||
do
|
||||
@ -365,34 +353,6 @@ std::string HTTPClientSession::proxyRequestPrefix() const
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSession::deleteResponseStream()
|
||||
{
|
||||
delete _pResponseStream;
|
||||
_pResponseStream = 0;
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSession::deleteRequestStream()
|
||||
{
|
||||
delete _pRequestStream;
|
||||
_pRequestStream = 0;
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSession::setResponseStream(std::istream* pRespStream)
|
||||
{
|
||||
poco_assert (!_pResponseStream);
|
||||
_pResponseStream = pRespStream;
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSession::setRequestStream(std::ostream* pRequestStream)
|
||||
{
|
||||
poco_assert (!_pRequestStream);
|
||||
_pRequestStream = pRequestStream;
|
||||
}
|
||||
|
||||
|
||||
bool HTTPClientSession::mustReconnect() const
|
||||
{
|
||||
if (!_mustReconnect)
|
||||
|
Loading…
x
Reference in New Issue
Block a user