[Libreoffice-commits] core.git: desktop/source
Stephan Bergmann (via logerrit)
logerrit at kemper.freedesktop.org
Fri Oct 23 15:05:52 UTC 2020
desktop/source/app/updater.cxx | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
New commits:
commit 11b7821b547fecadee5d59432483b170a42c25fb
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Fri Oct 23 10:38:10 2020 +0200
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Fri Oct 23 17:05:16 2020 +0200
Missing call to curl_easy_cleanup (--enable-online-update=mar)
<https://curl.haxx.se/libcurl/c/curl_easy_init.html> states that each call to
curl_easy_init "MUST have a corresponding call to curl_easy_cleanup". (And
<https://curl.haxx.se/libcurl/c/curl_easy_cleanup.html> states: "Passing in a
NULL pointer in handle will make this function return immediately with no
action.")
The call to curl_easy_cleanup appears to be missing ever since the code calling
curl_easy_init was introduced with 9c3b05f2d571b58ee2322a942162ecec654544dc
"improve update checker and update downloader code".
Change-Id: I5757efe131f73783c6f66a77d07676b8ce440f9d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104711
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/desktop/source/app/updater.cxx b/desktop/source/app/updater.cxx
index 2d99856b2174..2748373e5f62 100644
--- a/desktop/source/app/updater.cxx
+++ b/desktop/source/app/updater.cxx
@@ -43,6 +43,8 @@
#include <officecfg/Setup.hxx>
+#include <functional>
+#include <memory>
#include <set>
namespace {
@@ -538,13 +540,14 @@ size_t WriteCallbackFile(void *ptr, size_t size,
std::string download_content(const OString& rURL, bool bFile, OUString& rHash)
{
Updater::log("Download: " + rURL);
- CURL* curl = curl_easy_init();
+ std::unique_ptr<CURL, std::function<void(CURL *)>> curl(
+ curl_easy_init(), [](CURL * p) { curl_easy_cleanup(p); });
if (!curl)
return std::string();
- curl_easy_setopt(curl, CURLOPT_URL, rURL.getStr());
- curl_easy_setopt(curl, CURLOPT_USERAGENT, kUserAgent);
+ curl_easy_setopt(curl.get(), CURLOPT_URL, rURL.getStr());
+ curl_easy_setopt(curl.get(), CURLOPT_USERAGENT, kUserAgent);
bool bUseProxy = false;
if (bUseProxy)
{
@@ -557,18 +560,18 @@ std::string download_content(const OString& rURL, bool bFile, OUString& rHash)
char buf[] = "Expect:";
curl_slist* headerlist = nullptr;
headerlist = curl_slist_append(headerlist, buf);
- curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); // follow redirects
+ curl_easy_setopt(curl.get(), CURLOPT_HTTPHEADER, headerlist);
+ curl_easy_setopt(curl.get(), CURLOPT_FOLLOWLOCATION, 1); // follow redirects
// only allow redirect to http:// and https://
- curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
+ curl_easy_setopt(curl.get(), CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
std::string response_body;
utl::TempFile aTempFile;
WriteDataFile aFile(aTempFile.GetStream(StreamMode::WRITE));
if (!bFile)
{
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA,
+ curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, WriteCallback);
+ curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA,
static_cast<void *>(&response_body));
aTempFile.EnableKillingFile(true);
@@ -581,17 +584,17 @@ std::string download_content(const OString& rURL, bool bFile, OUString& rHash)
aTempFile.EnableKillingFile(false);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallbackFile);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA,
+ curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, WriteCallbackFile);
+ curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA,
static_cast<void *>(&aFile));
}
// Fail if 400+ is returned from the web server.
- curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
+ curl_easy_setopt(curl.get(), CURLOPT_FAILONERROR, 1);
- CURLcode cc = curl_easy_perform(curl);
+ CURLcode cc = curl_easy_perform(curl.get());
long http_code = 0;
- curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
+ curl_easy_getinfo(curl.get(), CURLINFO_RESPONSE_CODE, &http_code);
if (http_code != 200)
{
SAL_WARN("desktop.updater", "download did not succeed. Error code: " << http_code);
More information about the Libreoffice-commits
mailing list