Skip to content

Commit 45661cb

Browse files
committed
CCDBApi: avoid leaking curl handle.
1 parent f5ebb69 commit 45661cb

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

CCDB/include/CCDB/CCDBDownloader.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ typedef struct DownloaderRequestData {
5252
HeaderObjectPair_t hoPair;
5353
std::map<std::string, std::string>* headers;
5454
std::string userAgent;
55+
curl_slist* optionsList;
5556

5657
std::function<bool(std::string)> localContentCallback;
5758
} DownloaderRequestData;
@@ -296,6 +297,7 @@ class CCDBDownloader
296297
int hostInd;
297298
int locInd;
298299
DownloaderRequestData* requestData;
300+
curl_slist** options;
299301
} PerformData;
300302
#endif
301303

@@ -421,6 +423,6 @@ typedef struct DataForClosingSocket {
421423
curl_socket_t socket;
422424
} DataForClosingSocket;
423425

424-
} // namespace o2
426+
} // namespace o2::ccdb
425427

426428
#endif // O2_CCDB_CCDBDOWNLOADER_H

CCDB/src/CCDBDownloader.cxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,10 @@ void CCDBDownloader::transferFinished(CURL* easy_handle, CURLcode curlCode)
535535
}
536536
}
537537
--(*performData->requestsLeft);
538+
curl_slist_free_all(*performData->options);
538539
delete requestData;
539540
delete performData->codeDestination;
541+
curl_easy_cleanup(easy_handle);
540542
}
541543
} break;
542544
}
@@ -681,6 +683,7 @@ void CCDBDownloader::asynchSchedule(CURL* handle, size_t* requestCounter)
681683
curl_easy_getinfo(handle, CURLINFO_PRIVATE, &requestData);
682684
headerMap = &(requestData->hoPair.header);
683685
hostsPool = &(requestData->hosts);
686+
auto* options = &(requestData->optionsList);
684687

685688
// Prepare temporary data about transfer
686689
auto* data = new CCDBDownloader::PerformData(); // Freed in transferFinished
@@ -692,6 +695,7 @@ void CCDBDownloader::asynchSchedule(CURL* handle, size_t* requestCounter)
692695
data->hostInd = 0;
693696
data->locInd = 0;
694697
data->requestData = requestData;
698+
data->options = options;
695699

696700
// Prepare handle and schedule download
697701
setHandleOptions(handle, data);
@@ -719,4 +723,4 @@ std::string CCDBDownloader::prepareLogMessage(std::string host_url, std::string
719723
return fmt::format("CcdbDownloader finished transfer {}{}{} for {} (agent_id: {}) with http code: {}", host_url, (host_url.back() == '/') ? "" : "/", upath, (ts < 0) ? getCurrentTimestamp() : ts, userAgent, httpCode);
720724
}
721725

722-
} // namespace o2
726+
} // namespace o2::ccdb

CCDB/src/CcdbApi.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,7 @@ void CcdbApi::scheduleDownload(RequestContext& requestContext, size_t* requestCo
16561656
data->timestamp = requestContext.timestamp;
16571657
data->localContentCallback = localContentCallback;
16581658
data->userAgent = mUniqueAgentID;
1659+
data->optionsList = options_list;
16591660

16601661
curl_easy_setopt(curl_handle, CURLOPT_URL, fullUrl.c_str());
16611662
initCurlOptionsForRetrieve(curl_handle, (void*)(&data->hoPair), writeCallback, false);

CCDB/test/testCcdbApiDownloader.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ BOOST_AUTO_TEST_CASE(asynch_schedule_test)
172172
curl_easy_getinfo(handles[i], CURLINFO_HTTP_CODE, &httpCode);
173173
BOOST_CHECK(httpCode == 200);
174174
BOOST_CHECK(dests[i]->size() != 0);
175-
curl_easy_cleanup(handles[i]);
175+
// I suspect the following was needed simply because the rest of the
176+
// code was leaking.
177+
// curl_easy_cleanup(handles[i]);
176178
delete dests[i];
177179
}
178180
curl_global_cleanup();

0 commit comments

Comments
 (0)