=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ftp/fetch.c,v retrieving revision 1.172 retrieving revision 1.173 diff -u -r1.172 -r1.173 --- src/usr.bin/ftp/fetch.c 2019/10/09 16:43:22 1.172 +++ src/usr.bin/ftp/fetch.c 2019/10/13 15:07:13 1.173 @@ -1,4 +1,4 @@ -/* $OpenBSD: fetch.c,v 1.172 2019/10/09 16:43:22 jca Exp $ */ +/* $OpenBSD: fetch.c,v 1.173 2019/10/13 15:07:13 jca Exp $ */ /* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */ /*- @@ -76,6 +76,7 @@ int ftp_printf(FILE *, struct tls *, const char *, ...) __attribute__((format(printf, 3, 4))); char *ftp_readline(FILE *, struct tls *, size_t *); size_t ftp_read(FILE *, struct tls *, char *, size_t); +void ftp_close(FILE **fin, struct tls **tls, volatile int *fd); #ifndef NOSSL int proxy_connect(int, char *, char *); int SSL_vprintf(struct tls *, const char *, va_list); @@ -919,14 +920,7 @@ *loctail = '\0'; if (verbose) fprintf(ttyout, "Redirected to %s\n", redirurl); - if (fin != NULL) { - fclose(fin); - fin = NULL; - } - if (fd != -1) { - close(fd); - fd = -1; - } + ftp_close(&fin, &tls, &fd); rval = url_get(redirurl, proxyenv, savefile, lastfile); free(redirurl); goto cleanup_url_get; @@ -1063,26 +1057,10 @@ cleanup_url_get: #ifndef NOSSL - if (tls != NULL) { - if (tls_session_fd != -1) - dprintf(STDERR_FILENO, "tls session resumed: %s\n", - tls_conn_session_resumed(tls) ? "yes" : "no"); - do { - i = tls_close(tls); - } while (i == TLS_WANT_POLLIN || i == TLS_WANT_POLLOUT); - tls_free(tls); - } free(full_host); free(sslhost); #endif /* !NOSSL */ - if (fin != NULL) { - fclose(fin); - fin = NULL; - } - if (fd != -1) { - close(fd); - fd = -1; - } + ftp_close(&fin, &tls, &fd); if (out >= 0 && out != fileno(stdout)) close(out); free(buf); @@ -1592,6 +1570,33 @@ } #endif /* !SMALL */ return (ret); +} + +void +ftp_close(FILE **fin, struct tls **tls, volatile int *fd) +{ +#ifndef NOSSL + int ret; + + if (*tls != NULL) { + if (tls_session_fd != -1) + dprintf(STDERR_FILENO, "tls session resumed: %s\n", + tls_conn_session_resumed(*tls) ? "yes" : "no"); + do { + ret = tls_close(*tls); + } while (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT); + tls_free(*tls); + *tls = NULL; + } +#endif + if (*fin != NULL) { + fclose(*fin); + *fin = NULL; + } + if (*fd != -1) { + close(*fd); + *fd = -1; + } } #ifndef NOSSL