geomyidae

A small C-based gopherd. (gopher://bitreich.org/1/scm/geomyidae)
git clone git://r-36.net/geomyidae
Log | Files | Refs | README | LICENSE

commit aa6b70539a2b175efadad1d5f6a771d77a92f8ef
parent 206c57aca0611bef65a365710aaef32529634b5c
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 11 Nov 2018 14:00:02 +0100

simplify listfds handling

simplify:
- closing listfds, remove unneccesary >= fd check.
- use the same order of closing the log as in sighandler.
- don't check for NULL, free(NULL) is valid.

Signed-off-by: Christoph Lohmann <20h@r-36.net>

Diffstat:
main.c | 46++++++++++++++++++----------------------------
1 file changed, 18 insertions(+), 28 deletions(-)

diff --git a/main.c b/main.c @@ -271,14 +271,12 @@ sighandler(int sig) close(glfd); glfd = -1; } - if (listfds != NULL) { - for (i = 0; i < nlistfds; i++) { - if (listfds[i] >= 0) { - shutdown(listfds[i], SHUT_RDWR); - close(listfds[i]); - } - } + + for (i = 0; i < nlistfds; i++) { + shutdown(listfds[i], SHUT_RDWR); + close(listfds[i]); } + free(listfds); exit(0); break; default: @@ -583,11 +581,9 @@ main(int argc, char *argv[]) sizeof(*listfds) * ++nlistfds); listfds[nlistfds-1] = lfdret[j]; } - if (lfdret != NULL) - free(lfdret); + free(lfdret); } - if (bindips != NULL) - free(bindips); + free(bindips); if (nlistfds < 1) return 1; @@ -613,15 +609,12 @@ main(int argc, char *argv[]) if (dropprivileges(gr, us) < 0) { perror("dropprivileges"); - if (listfds != NULL) { - for (i = 0; i < nlistfds; i++) { - if (listfds[i] >= 0) { - shutdown(listfds[i], SHUT_RDWR); - close(listfds[i]); - } - } - free(listfds); + + for (i = 0; i < nlistfds; i++) { + shutdown(listfds[i], SHUT_RDWR); + close(listfds[i]); } + free(listfds); return 1; } @@ -734,21 +727,18 @@ main(int argc, char *argv[]) close(sock); } - if (listfds != NULL) { - for (i = 0; i < nlistfds; i++) { - if (listfds[i] >= 0) { - shutdown(listfds[i], SHUT_RDWR); - close(listfds[i]); - } - } - free(listfds); - } if (logfile != NULL && glfd != -1) { close(glfd); glfd = -1; } free(ohost); + for (i = 0; i < nlistfds; i++) { + shutdown(listfds[i], SHUT_RDWR); + close(listfds[i]); + } + free(listfds); + return 0; }