From 7d3ebd3d016b34a39c50bcaf9ae1b845a6a26b72 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Fri, 18 Mar 2022 03:29:33 +0000 Subject: [PATCH] GET queries, fix memleak on fetch error FossilOrigin-Name: 02a81343b2c2f4d56340ccb7947e517197d7ce67b4f8ff77032948705eb17cb3 --- src/request.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/request.c b/src/request.c index f130c00..37d806d 100644 --- a/src/request.c +++ b/src/request.c @@ -24,38 +24,39 @@ int mastodont_request(mastodont_t* data, struct mastodont_request_args* args) struct mstdnt_storage* storage = args->storage; struct mstdnt_fetch_results results = { 0 }; char* post; - char* + char* url_query = args->params_query ? + _mstdnt_query_string(data, args->url, args->params_query, args->params_query_len) : + args->url; storage->needs_cleanup = 0; - if (args->params_query) - { - - } - if (args->params_post) { post = _mstdnt_query_string(data, NULL, args->params_post, args->params_post_len); curl_easy_setopt(data->curl, CURLOPT_POSTFIELDS, post); } - if (mastodont_fetch_curl(data, args->url, &results, args->request_type) != CURLE_OK) - { - return 1; - } - - if (mstdnt_check_error(&results, storage)) + if (mastodont_fetch_curl(data, url_query, &results, args->request_type) != CURLE_OK) { res = 1; goto cleanup; } + if (mstdnt_check_error(&results, storage)) + { + res = 1; + goto cleanup_res; + } + /* Optional */ if (args->callback) args->callback(&results, storage, args->args); -cleanup: +cleanup_res: mastodont_fetch_results_cleanup(&results); +cleanup: if (args->params_post) free(post); + /* Only free if params_query set */ + if (args->params_query) free(url_query); return res; }