12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- From 9ab7dff9279f8640752ffc640dd90ad1dcd19a2b Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Tim=20R=C3=BChsen?= <tim.ruehsen@gmx.de>
- Date: Mon, 17 Feb 2020 21:40:22 +0100
- Subject: [PATCH 38/60] ping6: Fix memleak in ping_set_dest
- ---
- ping/ping6.c | 18 +++++++++++-------
- ping/ping6.h | 2 +-
- 2 files changed, 12 insertions(+), 8 deletions(-)
- diff --git a/ping/ping6.c b/ping/ping6.c
- index b0e0bf1f..8bc92a8f 100644
- --- a/ping/ping6.c
- +++ b/ping/ping6.c
- @@ -998,7 +998,7 @@ ping_recv (PING * p)
- }
-
- static int
- -ping_set_dest (PING * ping, char *host)
- +ping_set_dest (PING * ping, const char *host)
- {
- int err;
- struct addrinfo *result, hints;
- @@ -1008,8 +1008,9 @@ ping_set_dest (PING * ping, char *host)
- err = idna_to_ascii_lz (host, &rhost, 0);
- if (err)
- return 1;
- + host = rhost;
- #else /* !HAVE_IDN */
- - rhost = host;
- + rhost = NULL;
- #endif
-
- memset (&hints, 0, sizeof (hints));
- @@ -1022,19 +1023,22 @@ ping_set_dest (PING * ping, char *host)
- hints.ai_flags |= AI_CANONIDN;
- #endif
-
- - err = getaddrinfo (rhost, NULL, &hints, &result);
- + err = getaddrinfo (host, NULL, &hints, &result);
- if (err)
- - return 1;
- + {
- + free (rhost);
- + return 1;
- + }
-
- memcpy (&ping->ping_dest.ping_sockaddr6, result->ai_addr, result->ai_addrlen);
-
- if (result->ai_canonname)
- ping->ping_hostname = strdup (result->ai_canonname);
- else
- - ping->ping_hostname = strdup (rhost);
- -
- #if HAVE_IDN
- - free (rhost);
- + ping->ping_hostname = host;
- +#else
- + ping->ping_hostname = strdup (host);
- #endif
- freeaddrinfo (result);
-
- diff --git a/ping/ping6.h b/ping/ping6.h
- index 76fc6b09..b15a407f 100644
- --- a/ping/ping6.h
- +++ b/ping/ping6.h
- @@ -24,7 +24,7 @@
- #define USE_IPV6 1
-
- static PING *ping_init (int type, int ident);
- -static int ping_set_dest (PING * ping, char *host);
- +static int ping_set_dest (PING * ping, const char *host);
- static int ping_recv (PING * p);
- static int ping_xmit (PING * p);
-
- --
- 2.26.0.292.g33ef6b2f38
|