From 170afaf3a9708c91f666f7edcac2ce84f6ba38b7 Mon Sep 17 00:00:00 2001 From: tedu Date: Thu, 15 Oct 2015 22:21:28 +0000 Subject: [PATCH] it is perhaps better style to not call close() on -1, even if harmless --- usr.sbin/rebound/rebound.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/usr.sbin/rebound/rebound.c b/usr.sbin/rebound/rebound.c index 04fdf96e256..ebc98ec9336 100644 --- a/usr.sbin/rebound/rebound.c +++ b/usr.sbin/rebound/rebound.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rebound.c,v 1.13 2015/10/15 22:17:43 tedu Exp $ */ +/* $OpenBSD: rebound.c,v 1.14 2015/10/15 22:21:28 tedu Exp $ */ /* * Copyright (c) 2015 Ted Unangst * @@ -201,7 +201,8 @@ newrequest(int ud, struct sockaddr *remoteaddr) return req; fail: free(hit); - close(req->s); + if (req->s != -1) + close(req->s); free(req); return NULL; } @@ -241,8 +242,10 @@ freerequest(struct request *req) struct dnscache *ent; TAILQ_REMOVE(&reqfifo, req, fifo); - close(req->client); - close(req->s); + if (req->client != -1) + close(req->client); + if (req->s != -1) + close(req->s); if ((ent = req->cacheent) && !ent->resp) { free(ent->req); free(ent); @@ -288,9 +291,12 @@ newtcprequest(int ld, struct sockaddr *remoteaddr) req->ts.tv_sec += 30; return req; + fail: - close(req->s); - close(req->client); + if (req->s != -1) + close(req->s); + if (req->client != -1) + close(req->client); free(req); return NULL; } -- 2.20.1