Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: catch all curl_slist_append failures #140

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 0 additions & 116 deletions .github/workflows/release.yml

This file was deleted.

2 changes: 1 addition & 1 deletion src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct curl_slist *pg_text_array_to_slist(ArrayType *array,
}

hdr = TextDatumGetCString(value);
headers = curl_slist_append(headers, hdr);
CURL_SLIST_APPEND(headers, hdr);
pfree(hdr);
}
array_free_iterator(iterator);
Expand Down
8 changes: 8 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
ereport(ERROR, errmsg("Could not curl_easy_getinfo(%s)", #opt)); \
} while (0)

#define CURL_SLIST_APPEND(list, str) \
do { \
struct curl_slist *new_list = curl_slist_append(list, str); \
if (new_list == NULL) \
ereport(ERROR, errmsg("curl_slist_append returned NULL")); \
list = new_list; \
} while (0)

#define EREPORT_NULL_ATTR(tupIsNull, attr) \
do { \
if (tupIsNull) \
Expand Down
15 changes: 6 additions & 9 deletions src/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ static void init_curl_handle(CURLM *curl_mhandle, CurlData *cdata, char *url, ch
ereport(ERROR, errmsg("curl_multi_add_handle returned %s", curl_multi_strerror(code)));
}


static void consume_request_queue(CURLM *curl_mhandle){
int ret_code = SPI_execute_with_args("\
WITH\
Expand Down Expand Up @@ -245,28 +244,26 @@ static void consume_request_queue(CURLM *curl_mhandle){

CurlData *cdata = palloc(sizeof(CurlData));

struct curl_slist *request_headers = NULL;
Datum headersBin = SPI_getbinval(SPI_tuptable->vals[j], SPI_tuptable->tupdesc, 5, &tupIsNull);

if (!tupIsNull) {
ArrayType *pgHeaders = DatumGetArrayTypeP(headersBin);
struct curl_slist *request_headers = NULL;

request_headers = pg_text_array_to_slist(pgHeaders, request_headers);

CURL_SLIST_APPEND(request_headers, "User-Agent: pg_net/" EXTVERSION);

cdata->request_headers = request_headers;
}

char *reqBody = NULL;
Datum bodyBin = SPI_getbinval(SPI_tuptable->vals[j], SPI_tuptable->tupdesc, 6, &tupIsNull);
if (!tupIsNull) reqBody = TextDatumGetCString(bodyBin);


cdata->body = makeStringInfo();
cdata->id = id;

struct curl_slist *new_headers = curl_slist_append(request_headers, "User-Agent: pg_net/" EXTVERSION);
if(new_headers == NULL)
ereport(ERROR, errmsg("curl_slist_append returned NULL"));

cdata->request_headers = new_headers;

init_curl_handle(curl_mhandle, cdata, url, reqBody, method, timeout_milliseconds);
}
}
Expand Down