Skip to content

Commit 68ef0bf

Browse files
authored
fix: a couple of memory leaks (#273)
1 parent 35907eb commit 68ef0bf

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/util.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,19 @@ Datum _urlencode_string(PG_FUNCTION_ARGS) {
1414
char *str = text_to_cstring(PG_GETARG_TEXT_P(0));
1515
char *urlencoded_str = NULL;
1616

17-
urlencoded_str = curl_escape(str, strlen(str));
17+
urlencoded_str = curl_easy_escape(NULL, str, strlen(str));
18+
19+
if (urlencoded_str == NULL) {
20+
PG_RETURN_NULL();
21+
}
1822

1923
pfree(str);
2024

21-
PG_RETURN_TEXT_P(cstring_to_text(urlencoded_str));
25+
text *result = cstring_to_text(urlencoded_str);
26+
27+
curl_free(urlencoded_str);
28+
29+
PG_RETURN_TEXT_P(result);
2230
}
2331

2432
Datum _encode_url_with_params_array(PG_FUNCTION_ARGS) {
@@ -52,5 +60,9 @@ Datum _encode_url_with_params_array(PG_FUNCTION_ARGS) {
5260
pfree(url);
5361
curl_url_cleanup(h);
5462

55-
PG_RETURN_TEXT_P(cstring_to_text(full_url));
63+
text *result = cstring_to_text(full_url);
64+
65+
curl_free(full_url);
66+
67+
PG_RETURN_TEXT_P(result);
5668
}

0 commit comments

Comments
 (0)