summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: af62220)
raw | patch | inline | side by side (parent: af62220)
author | Tolga Ceylan <tolga.ceylan@gmail.com> | |
Sun, 20 Mar 2016 02:03:31 +0000 (19:03 -0700) | ||
committer | Tolga Ceylan <tolga.ceylan@gmail.com> | |
Sun, 20 Mar 2016 02:03:31 +0000 (19:03 -0700) |
slist of http headers require cleanup to avoid
memory leak. See libcurl example:
https://curl.haxx.se/libcurl/c/httpcustomheader.html
memory leak. See libcurl example:
https://curl.haxx.se/libcurl/c/httpcustomheader.html
src/write_http.c | patch | blob | history |
diff --git a/src/write_http.c b/src/write_http.c
index bfb5524c936c699f3545640f7f6d0d17ce9b615b..bbd94af1408931da2bdac41f31cafda6c33644c6 100644 (file)
--- a/src/write_http.c
+++ b/src/write_http.c
int format;
CURL *curl;
+ struct curl_slist *headers;
char curl_errbuf[CURL_ERROR_SIZE];
char send_buffer[4096];
static int wh_callback_init (wh_callback_t *cb) /* {{{ */
{
- struct curl_slist *headers;
-
if (cb->curl != NULL)
return (0);
curl_easy_setopt (cb->curl, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt (cb->curl, CURLOPT_USERAGENT, PACKAGE_NAME"/"PACKAGE_VERSION);
- headers = NULL;
- headers = curl_slist_append (headers, "Accept: */*");
+ cb->headers = NULL;
+ cb->headers = curl_slist_append (cb->headers, "Accept: */*");
if (cb->format == WH_FORMAT_JSON)
- headers = curl_slist_append (headers, "Content-Type: application/json");
+ cb->headers = curl_slist_append (cb->headers, "Content-Type: application/json");
else
- headers = curl_slist_append (headers, "Content-Type: text/plain");
- headers = curl_slist_append (headers, "Expect:");
- curl_easy_setopt (cb->curl, CURLOPT_HTTPHEADER, headers);
+ cb->headers = curl_slist_append (cb->headers, "Content-Type: text/plain");
+ cb->headers = curl_slist_append (cb->headers, "Expect:");
+ curl_easy_setopt (cb->curl, CURLOPT_HTTPHEADER, cb->headers);
curl_easy_setopt (cb->curl, CURLOPT_ERRORBUFFER, cb->curl_errbuf);
curl_easy_setopt (cb->curl, CURLOPT_URL, cb->location);
wh_flush_nolock (/* timeout = */ 0, cb);
curl_easy_cleanup (cb->curl);
+
+ if (cb->headers != NULL)
+ {
+ curl_slist_free_all (cb->headers);
+ cb->headers = NULL;
+ }
+
sfree (cb->location);
sfree (cb->user);
sfree (cb->pass);
cb->cacert = NULL;
cb->format = WH_FORMAT_COMMAND;
cb->curl = NULL;
+ cb->headers = NULL;
pthread_mutex_init (&cb->send_lock, /* attr = */ NULL);