mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-27 04:32:55 +00:00
Fix segfault in ccurl_thread.cc
curl_global_init() is not thread-safe, it must be called at the start of main()
This commit is contained in:
parent
0d9052b83b
commit
77d4a55dcc
@ -105,34 +105,31 @@ void ccurl_fetch_data(thread_handle &handle, const ccurl_location_ptr &curloc)
|
||||
chunk.memory = NULL;
|
||||
chunk.size = 0;
|
||||
|
||||
if (curl_global_init(CURL_GLOBAL_ALL) == 0) {
|
||||
curl = curl_easy_init();
|
||||
if (curl) {
|
||||
DBGP("reading curl data from '%s'", curloc->uri);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, curloc->uri);
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ccurl_write_memory_callback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &chunk);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "conky-curl/1.0");
|
||||
curl = curl_easy_init();
|
||||
if (curl) {
|
||||
DBGP("reading curl data from '%s'", curloc->uri);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, curloc->uri);
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ccurl_write_memory_callback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &chunk);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "conky-curl/1.0");
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
if (res == CURLE_OK && chunk.size) {
|
||||
long http_status_code;
|
||||
res = curl_easy_perform(curl);
|
||||
if (res == CURLE_OK && chunk.size) {
|
||||
long http_status_code;
|
||||
|
||||
if(curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status_code) == CURLE_OK && http_status_code == 200) {
|
||||
std::lock_guard<std::mutex> lock(handle.mutex());
|
||||
curloc->process_function(curloc->result, chunk.memory);
|
||||
} else {
|
||||
NORM_ERR("curl: no data from server");
|
||||
}
|
||||
free(chunk.memory);
|
||||
if(curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status_code) == CURLE_OK && http_status_code == 200) {
|
||||
std::lock_guard<std::mutex> lock(handle.mutex());
|
||||
curloc->process_function(curloc->result, chunk.memory);
|
||||
} else {
|
||||
NORM_ERR("curl: no data from server");
|
||||
}
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
free(chunk.memory);
|
||||
} else {
|
||||
NORM_ERR("curl: no data from server");
|
||||
}
|
||||
curl_global_cleanup();
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
}
|
||||
|
||||
|
12
src/conky.cc
12
src/conky.cc
@ -77,6 +77,9 @@
|
||||
#if defined BUILD_WEATHER_XOAP || defined BUILD_RSS
|
||||
#include <libxml/parser.h>
|
||||
#endif
|
||||
#ifdef BUILD_CURL
|
||||
#include <curl/curl.h>
|
||||
#endif
|
||||
|
||||
/* local headers */
|
||||
#include "core.h"
|
||||
@ -4401,6 +4404,11 @@ int main(int argc, char **argv)
|
||||
tcp_portmon_set_max_connections(0);
|
||||
#endif
|
||||
|
||||
#ifdef BUILD_CURL
|
||||
if(curl_global_init(CURL_GLOBAL_ALL))
|
||||
NORM_ERR("curl_global_init() failed, you may not be able to use curl variables");
|
||||
#endif
|
||||
|
||||
/* handle command line parameters that don't change configs */
|
||||
#ifdef BUILD_X11
|
||||
if(isutf8("LC_ALL") || isutf8("LC_CTYPE") || isutf8("LANG")) {
|
||||
@ -4480,6 +4488,10 @@ int main(int argc, char **argv)
|
||||
|
||||
main_loop();
|
||||
|
||||
#ifdef BUILD_CURL
|
||||
curl_global_cleanup();
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
kvm_close(kd);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user