GET queries, fix memleak on fetch error

FossilOrigin-Name: 02a81343b2c2f4d56340ccb7947e517197d7ce67b4f8ff77032948705eb17cb3
This commit is contained in:
me@ow.nekobit.net 2022-03-18 03:29:33 +00:00
parent ced55925b7
commit 7d3ebd3d01

View file

@ -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;
}