From df11705edb0dc42b30d625081d43c4378dbe95b1 Mon Sep 17 00:00:00 2001 From: Stanley Hopcroft Date: Wed, 1 Dec 2004 08:28:36 +0000 Subject: 1075725: patch to my_connect() to deal with SEGV if connect fails git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@960 f882894a-f735-0410-b71e-b25c423dba1c --- plugins/netutils.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/netutils.c b/plugins/netutils.c index c99983f0..aee53d35 100644 --- a/plugins/netutils.c +++ b/plugins/netutils.c @@ -213,7 +213,7 @@ static int my_connect (const char *host_name, int port, int *sd, int proto) { struct addrinfo hints; - struct addrinfo *res; + struct addrinfo *res, *res0; char port_str[6]; int result; @@ -223,13 +223,14 @@ my_connect (const char *host_name, int port, int *sd, int proto) hints.ai_socktype = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM; snprintf (port_str, sizeof (port_str), "%d", port); - result = getaddrinfo (host_name, port_str, &hints, &res); + result = getaddrinfo (host_name, port_str, &hints, &res0); if (result != 0) { printf ("%s\n", gai_strerror (result)); return STATE_UNKNOWN; } else { + res = res0; while (res) { /* attempt to create a socket */ *sd = socket (res->ai_family, (proto == IPPROTO_UDP) ? @@ -260,7 +261,7 @@ my_connect (const char *host_name, int port, int *sd, int proto) close (*sd); res = res->ai_next; } - freeaddrinfo (res); + freeaddrinfo (res0); } if (result == 0) -- cgit v1.2.3-74-g34f1