diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-06-18 14:24:51 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-06-18 14:24:51 +0200 |
commit | 6e9bb3405a731442274c6c2fe99983f1d413b1f9 (patch) | |
tree | 091c45ebd059dfce3d9d362a3d0ba7a5144804da | |
parent | 136adb0f87a645b392fef587a06fc34d4698f3ed (diff) | |
download | gnunet-6e9bb3405a731442274c6c2fe99983f1d413b1f9.tar.gz gnunet-6e9bb3405a731442274c6c2fe99983f1d413b1f9.zip |
fix memory leak
-rw-r--r-- | src/curl/curl.c | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/src/curl/curl.c b/src/curl/curl.c index 749094800..020cdc24f 100644 --- a/src/curl/curl.c +++ b/src/curl/curl.c | |||
@@ -111,7 +111,6 @@ struct GNUNET_CURL_Job | |||
111 | * after the job has finished. | 111 | * after the job has finished. |
112 | */ | 112 | */ |
113 | struct curl_slist *job_headers; | 113 | struct curl_slist *job_headers; |
114 | |||
115 | }; | 114 | }; |
116 | 115 | ||
117 | 116 | ||
@@ -161,7 +160,6 @@ struct GNUNET_CURL_Context | |||
161 | * Closure for @e cb. | 160 | * Closure for @e cb. |
162 | */ | 161 | */ |
163 | void *cb_cls; | 162 | void *cb_cls; |
164 | |||
165 | }; | 163 | }; |
166 | 164 | ||
167 | 165 | ||
@@ -213,7 +211,8 @@ GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, void *cb_cls) | |||
213 | * @param header_name name of the header to send. | 211 | * @param header_name name of the header to send. |
214 | */ | 212 | */ |
215 | void | 213 | void |
216 | GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx, const char *header_name) | 214 | GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx, |
215 | const char *header_name) | ||
217 | { | 216 | { |
218 | ctx->async_scope_id_header = header_name; | 217 | ctx->async_scope_id_header = header_name; |
219 | } | 218 | } |
@@ -279,30 +278,26 @@ download_cb (char *bufptr, size_t size, size_t nitems, void *cls) | |||
279 | */ | 278 | */ |
280 | struct GNUNET_CURL_Job * | 279 | struct GNUNET_CURL_Job * |
281 | GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx, | 280 | GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx, |
282 | CURL *eh, | 281 | CURL *eh, |
283 | const struct curl_slist *job_headers, | 282 | const struct curl_slist *job_headers, |
284 | GNUNET_CURL_JobCompletionCallback jcc, | 283 | GNUNET_CURL_JobCompletionCallback jcc, |
285 | void *jcc_cls) | 284 | void *jcc_cls) |
286 | { | 285 | { |
287 | struct GNUNET_CURL_Job *job; | 286 | struct GNUNET_CURL_Job *job; |
288 | struct curl_slist *all_headers = NULL; | 287 | struct curl_slist *all_headers = NULL; |
289 | 288 | ||
290 | for (const struct curl_slist *curr = job_headers; | 289 | for (const struct curl_slist *curr = job_headers; curr != NULL; |
291 | curr != NULL; | ||
292 | curr = curr->next) | 290 | curr = curr->next) |
293 | { | 291 | { |
294 | GNUNET_assert ( | 292 | GNUNET_assert (NULL != |
295 | NULL != (all_headers = | 293 | (all_headers = curl_slist_append (all_headers, curr->data))); |
296 | curl_slist_append (all_headers, curr->data))); | ||
297 | } | 294 | } |
298 | 295 | ||
299 | for (const struct curl_slist *curr = ctx->common_headers; | 296 | for (const struct curl_slist *curr = ctx->common_headers; curr != NULL; |
300 | curr != NULL; | ||
301 | curr = curr->next) | 297 | curr = curr->next) |
302 | { | 298 | { |
303 | GNUNET_assert ( | 299 | GNUNET_assert (NULL != |
304 | NULL != (all_headers = | 300 | (all_headers = curl_slist_append (all_headers, curr->data))); |
305 | curl_slist_append (all_headers, curr->data))); | ||
306 | } | 301 | } |
307 | 302 | ||
308 | if (NULL != ctx->async_scope_id_header) | 303 | if (NULL != ctx->async_scope_id_header) |
@@ -313,8 +308,10 @@ GNUNET_CURL_job_add2 (struct GNUNET_CURL_Context *ctx, | |||
313 | if (GNUNET_YES == scope.have_scope) | 308 | if (GNUNET_YES == scope.have_scope) |
314 | { | 309 | { |
315 | char *aid_header = NULL; | 310 | char *aid_header = NULL; |
316 | aid_header = GNUNET_STRINGS_data_to_string_alloc (&scope.scope_id, | 311 | aid_header = |
317 | sizeof (struct GNUNET_AsyncScopeId)); | 312 | GNUNET_STRINGS_data_to_string_alloc (&scope.scope_id, |
313 | sizeof ( | ||
314 | struct GNUNET_AsyncScopeId)); | ||
318 | GNUNET_assert (NULL != aid_header); | 315 | GNUNET_assert (NULL != aid_header); |
319 | GNUNET_assert (NULL != curl_slist_append (all_headers, aid_header)); | 316 | GNUNET_assert (NULL != curl_slist_append (all_headers, aid_header)); |
320 | GNUNET_free (aid_header); | 317 | GNUNET_free (aid_header); |
@@ -378,7 +375,9 @@ GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx, | |||
378 | GNUNET_CURL_JobCompletionCallback jcc, | 375 | GNUNET_CURL_JobCompletionCallback jcc, |
379 | void *jcc_cls) | 376 | void *jcc_cls) |
380 | { | 377 | { |
378 | struct GNUNET_CURL_Job *job; | ||
381 | struct curl_slist *job_headers = NULL; | 379 | struct curl_slist *job_headers = NULL; |
380 | |||
382 | if (GNUNET_YES == add_json) | 381 | if (GNUNET_YES == add_json) |
383 | { | 382 | { |
384 | GNUNET_assert ( | 383 | GNUNET_assert ( |
@@ -386,7 +385,9 @@ GNUNET_CURL_job_add (struct GNUNET_CURL_Context *ctx, | |||
386 | curl_slist_append (NULL, "Content-Type: application/json"))); | 385 | curl_slist_append (NULL, "Content-Type: application/json"))); |
387 | } | 386 | } |
388 | 387 | ||
389 | return GNUNET_CURL_job_add2 (ctx, eh, job_headers, jcc, jcc_cls); | 388 | job = GNUNET_CURL_job_add2 (ctx, eh, job_headers, jcc, jcc_cls); |
389 | curl_slist_free_all (job_headers); | ||
390 | return job; | ||
390 | } | 391 | } |
391 | 392 | ||
392 | 393 | ||