]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ares: fix leak in tracing
authorStefan Eissing <stefan@eissing.org>
Tue, 23 Sep 2025 07:55:11 +0000 (09:55 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 24 Sep 2025 12:06:24 +0000 (14:06 +0200)
When DNS tracing is enabled, a string allocated by ares was not freed.

Reported-by: jmaggard10 on github
Bug: https://github.com/curl/curl/pull/18251#pullrequestreview-3255785083
Closes #18691

lib/asyn-ares.c
lib/curl_trc.h

index 807ca5c0bd0048ea9f3acd5e7c7c363935249d12..0a04f4cc367fdaa0ccaa10c35739a07db5ddfdcb 100644 (file)
@@ -747,8 +747,11 @@ struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data,
   ares->result = CURLE_OK;
 
 #if ARES_VERSION >= 0x011800  /* >= v1.24.0 */
-  CURL_TRC_DNS(data, "asyn-ares: servers=%s",
-               ares_get_servers_csv(ares->channel));
+  if(CURL_TRC_DNS_is_verbose(data)) {
+    char *csv = ares_get_servers_csv(ares->channel);
+    CURL_TRC_DNS(data, "asyn-ares: servers=%s", csv);
+    ares_free_string(csv);
+  }
 #endif
 
 #ifdef HAVE_CARES_GETADDRINFO
index 2819abe2dd481d1fd0fb9ad1b074c5778bd1246c..37a373e4a6a679401be44c51732e3d0f487bc4c1 100644 (file)
@@ -123,6 +123,8 @@ void Curl_trc_ws(struct Curl_easy *data,
 
 #define CURL_TRC_M_is_verbose(data) \
   Curl_trc_ft_is_verbose(data, &Curl_trc_feat_multi)
+#define CURL_TRC_DNS_is_verbose(data) \
+  Curl_trc_ft_is_verbose(data, &Curl_trc_feat_dns)
 
 #if defined(CURL_HAVE_C99) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
 #define infof(data, ...) \
@@ -141,7 +143,7 @@ void Curl_trc_ws(struct Curl_easy *data,
   do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_read)) \
          Curl_trc_read(data, __VA_ARGS__); } while(0)
 #define CURL_TRC_DNS(data, ...) \
-  do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_dns)) \
+  do { if(CURL_TRC_DNS_is_verbose(data)) \
          Curl_trc_dns(data, __VA_ARGS__); } while(0)
 
 #ifndef CURL_DISABLE_FTP