From 316b5ea579021df143612e4dda9d2a4a7d0baf5e Mon Sep 17 00:00:00 2001 From: Esteban Sanchez Date: Tue, 27 Mar 2007 11:06:56 +0200 Subject: [PATCH] Close the filedescriptor in `ping_free', not `ping_host_remove'. --- src/liboping.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/liboping.c b/src/liboping.c index f749301..9b91b6d 100644 --- a/src/liboping.c +++ b/src/liboping.c @@ -778,6 +778,7 @@ static pinghost_t *ping_alloc (void) ph->addr = (struct sockaddr_storage *) (ph->timer + 1); ph->addrlen = sizeof (struct sockaddr_storage); + ph->fd = -1; ph->latency = -1.0; ph->ident = ping_get_ident () & 0xFFFF; @@ -786,6 +787,9 @@ static pinghost_t *ping_alloc (void) static void ping_free (pinghost_t *ph) { + if (ph->fd >= 0) + close (ph->fd); + if (ph->hostname != NULL) free (ph->hostname); @@ -1152,8 +1156,7 @@ int ping_host_add (pingobj_t *obj, const char *host) if (ph->fd < 0) { - free (ph->hostname); - free (ph); + ping_free (ph); return (-1); } @@ -1210,9 +1213,6 @@ int ping_host_remove (pingobj_t *obj, const char *host) else pre->next = cur->next; - if (cur->fd >= 0) - close (cur->fd); - ping_free (cur); return (0); -- 2.11.0