diff options
author | Stefan Radomski <github@mintwerk.de> | 2016-06-13 08:52:55 (GMT) |
---|---|---|
committer | Stefan Radomski <github@mintwerk.de> | 2016-06-13 08:52:55 (GMT) |
commit | 053e9bc973fbe88fc41a34064ffadc0deabac58d (patch) | |
tree | 6aeee286577159ffcb612d41972a9d18ab685c6d /src/uscxml/util/URL.cpp | |
parent | 6e13c7b6e0888323223afd5d2e36e86243df57af (diff) | |
download | uscxml-053e9bc973fbe88fc41a34064ffadc0deabac58d.zip uscxml-053e9bc973fbe88fc41a34064ffadc0deabac58d.tar.gz uscxml-053e9bc973fbe88fc41a34064ffadc0deabac58d.tar.bz2 |
Fixed dozens of memory leaks
Diffstat (limited to 'src/uscxml/util/URL.cpp')
-rw-r--r-- | src/uscxml/util/URL.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/uscxml/util/URL.cpp b/src/uscxml/util/URL.cpp index a76c772..2e98fce 100644 --- a/src/uscxml/util/URL.cpp +++ b/src/uscxml/util/URL.cpp @@ -118,6 +118,8 @@ URLImpl::URLImpl(const std::string& url) : _orig(url), _handle(NULL), _isDownloa URLImpl::~URLImpl() { uriFreeUriMembersA(&_uri); + if (_handle != NULL) + curl_easy_cleanup(_handle); } URL URLImpl::resolve(URLImpl* relative, URLImpl* absolute) { @@ -590,7 +592,7 @@ void URLFetcher::fetchURL(URL& url) { char* header = (char*)malloc(paramIter->first.size() + strlen(value) + 3); sprintf(header,"%s: %s", paramIter->first.c_str(), value); headers = curl_slist_append(headers, header); - + free(header); // curl_free(key); // curl_free(value); paramIter++; @@ -598,11 +600,12 @@ void URLFetcher::fetchURL(URL& url) { // Disable "Expect: 100-continue" headers = curl_slist_append(headers, "Expect:"); + instance->_handlesToHeaders[handle] = headers; - (curlError = curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers)) == CURLE_OK || + (curlError = curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers)) == CURLE_OK || LOG(ERROR) << "Cannot headers for " << std::string(url) << ": " << curl_easy_strerror(curlError); - //curl_slist_free_all(headers); +// curl_slist_free_all(headers); } else if (url._impl->_requestType == URLRequestType::GET) { @@ -629,6 +632,10 @@ void URLFetcher::breakURL(URL& url) { curl_multi_remove_handle(instance->_multiHandle, handle); instance->_handlesToURLs.erase(handle); } + if (instance->_handlesToHeaders.find(handle) != instance->_handlesToHeaders.end()) { + curl_slist_free_all(instance->_handlesToHeaders[handle]); + instance->_handlesToHeaders.erase(handle); + } } void URLFetcher::start() { @@ -745,7 +752,6 @@ void URLFetcher::perform() { LOG(WARNING) << "curl_multi_remove_handle: " << curl_multi_strerror(err); } - _handlesToURLs.erase(msg->easy_handle); break; default: _handlesToURLs[msg->easy_handle]._impl->downloadFailed(msg->data.result); @@ -753,9 +759,13 @@ void URLFetcher::perform() { if (err != CURLM_OK) { LOG(WARNING) << "curl_multi_remove_handle: " << curl_multi_strerror(err); } + break; - _handlesToURLs.erase(msg->easy_handle); } + _handlesToURLs.erase(msg->easy_handle); + curl_slist_free_all(_handlesToHeaders[msg->easy_handle]); + _handlesToHeaders.erase(msg->easy_handle); + } else { LOG(ERROR) << "Curl reports info on unfinished download?!"; } |