utils

small programs, scripts and utils
git clone https://git.e1e0.net/utils.git
Log | Files | Refs

commit 517e16b2477f858dc573f7936c82f2b58be8f6a0
parent 4f06483349053777e96e1cf63dcd7d08b53c5c3a
Author: Paco Esteban <paco@e1e0.net>
Date:   Thu,  6 Aug 2020 18:05:48 +0200

hopefully better error check on make_api_call

Diffstat:
Mgeoloc/geoloc.c | 16+++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/geoloc/geoloc.c b/geoloc/geoloc.c @@ -61,6 +61,7 @@ make_api_call(char *url) { CURL *curl_handle; CURLcode res; struct MemoryStruct *chunk = malloc(sizeof(struct MemoryStruct)); + int ret = 0; chunk->memory = malloc(1); /* will be grown as needed */ chunk->size = 0; /* no data at this point */ @@ -76,17 +77,22 @@ make_api_call(char *url) { res = curl_easy_perform(curl_handle); - if(res != CURLE_OK) - return -1; + if(res != CURLE_OK) { + ret = -1; + goto out; + } /* * Now, our chunk.memory points to a memory block that is * chunk.size bytes big and contains the remote file. * We'll now parse the json response and print the data. */ - if (print_data(chunk->memory) == -1) - return -1; + if (print_data(chunk->memory) == -1) { + ret = -1; + goto out; + } +out: /* cleanup curl stuff */ curl_easy_cleanup(curl_handle); curl_global_cleanup(); @@ -94,7 +100,7 @@ make_api_call(char *url) { free(chunk->memory); free(chunk); - return 0; + return ret; } int