Fix #17 (curl_slist memory leak)

pull/40/head
Vitaliy Filippov 2015-07-04 00:18:59 +03:00
parent 5da32905ea
commit 1d47616518
2 changed files with 8 additions and 4 deletions

View File

@ -91,6 +91,8 @@ struct CurlAgent::Impl
DataStream *dest ;
} ;
static struct curl_slist* SetHeader( CURL* handle, const Header& hdr );
CurlAgent::CurlAgent() :
m_pimpl( new Impl )
{
@ -166,10 +168,12 @@ long CurlAgent::ExecCurl(
::curl_easy_setopt(curl, CURLOPT_WRITEDATA, this ) ;
m_pimpl->dest = dest ;
SetHeader( hdr ) ;
struct curl_slist *slist = SetHeader( m_pimpl->curl, hdr ) ;
CURLcode curl_code = ::curl_easy_perform(curl);
curl_slist_free_all(slist);
// get the HTTP response code
long http_code = 0;
::curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
@ -288,14 +292,15 @@ long CurlAgent::Custom(
return ExecCurl( url, dest, hdr ) ;
}
void CurlAgent::SetHeader( const Header& hdr )
static struct curl_slist* SetHeader( CURL *handle, const Header& hdr )
{
// set headers
struct curl_slist *curl_hdr = 0 ;
for ( Header::iterator i = hdr.begin() ; i != hdr.end() ; ++i )
curl_hdr = curl_slist_append( curl_hdr, i->c_str() ) ;
::curl_easy_setopt( m_pimpl->curl, CURLOPT_HTTPHEADER, curl_hdr ) ;
::curl_easy_setopt( handle, CURLOPT_HTTPHEADER, curl_hdr ) ;
return curl_hdr;
}
std::string CurlAgent::LastError() const

View File

@ -82,7 +82,6 @@ private :
static std::size_t HeaderCallback( void *ptr, size_t size, size_t nmemb, CurlAgent *pthis ) ;
static std::size_t Receive( void* ptr, size_t size, size_t nmemb, CurlAgent *pthis ) ;
void SetHeader( const Header& hdr ) ;
long ExecCurl(
const std::string& url,
DataStream *dest,