From e861c0ceb4634231e686e52c4bd73a992948de14 Mon Sep 17 00:00:00 2001 From: Raminder Singh Date: Wed, 5 Aug 2026 10:00:46 +0530 Subject: [PATCH] fix: a couple of memory leaks --- src/util.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/util.c b/src/util.c index 108d379e..a532a65d 100644 --- a/src/util.c +++ b/src/util.c @@ -14,11 +14,19 @@ Datum _urlencode_string(PG_FUNCTION_ARGS) { char *str = text_to_cstring(PG_GETARG_TEXT_P(0)); char *urlencoded_str = NULL; - urlencoded_str = curl_escape(str, strlen(str)); + urlencoded_str = curl_easy_escape(NULL, str, strlen(str)); + + if (urlencoded_str == NULL) { + PG_RETURN_NULL(); + } pfree(str); - PG_RETURN_TEXT_P(cstring_to_text(urlencoded_str)); + text *result = cstring_to_text(urlencoded_str); + + curl_free(urlencoded_str); + + PG_RETURN_TEXT_P(result); } Datum _encode_url_with_params_array(PG_FUNCTION_ARGS) { @@ -52,5 +60,9 @@ Datum _encode_url_with_params_array(PG_FUNCTION_ARGS) { pfree(url); curl_url_cleanup(h); - PG_RETURN_TEXT_P(cstring_to_text(full_url)); + text *result = cstring_to_text(full_url); + + curl_free(full_url); + + PG_RETURN_TEXT_P(result); }