=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ftp/fetch.c,v retrieving revision 1.188 retrieving revision 1.189 diff -u -r1.188 -r1.189 --- src/usr.bin/ftp/fetch.c 2020/02/13 15:47:33 1.188 +++ src/usr.bin/ftp/fetch.c 2020/02/13 15:54:10 1.189 @@ -1,4 +1,4 @@ -/* $OpenBSD: fetch.c,v 1.188 2020/02/13 15:47:33 jca Exp $ */ +/* $OpenBSD: fetch.c,v 1.189 2020/02/13 15:54:10 jca Exp $ */ /* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */ /*- @@ -77,7 +77,7 @@ static char *urldecode(const char *); static char *recode_credentials(const char *_userinfo); static char *ftp_readline(FILE *, size_t *); -static void ftp_close(FILE **, struct tls **, volatile int *); +static void ftp_close(FILE **, struct tls **, int *); static const char *sockerror(struct tls *); #ifdef SMALL #define ftp_printf(fp, ...) fprintf(fp, __VA_ARGS__) @@ -311,13 +311,13 @@ char pbuf[NI_MAXSERV], hbuf[NI_MAXHOST], *cp, *portnum, *path, ststr[4]; char *hosttail, *cause = "unknown", *newline, *host, *port, *buf = NULL; char *epath, *redirurl, *loctail, *h, *p, gerror[200]; - int error, i, isftpurl = 0, isredirect = 0, rval = -1; + int error, isftpurl = 0, isredirect = 0, rval = -1; int isunavail = 0, retryafter = -1; struct addrinfo hints, *res0, *res; - const char * volatile savefile; - char * volatile proxyurl = NULL; + const char *savefile; + char *proxyurl = NULL; char *credentials = NULL; - volatile int fd = -1, out = -1; + int fd = -1, out = -1; volatile sig_t oldintr, oldinti; FILE *fin = NULL; off_t hashbytes; @@ -1017,6 +1017,10 @@ #endif } + free(buf); + if ((buf = malloc(buflen)) == NULL) + errx(1, "Can't allocate memory for transfer buffer"); + /* Trap signals */ oldintr = NULL; oldinti = NULL; @@ -1033,11 +1037,7 @@ hashbytes = mark; progressmeter(-1, path); - free(buf); - /* Finally, suck down the file. */ - if ((buf = malloc(buflen)) == NULL) - errx(1, "Can't allocate memory for transfer buffer"); oldinti = signal(SIGINFO, psummary); if (chunked) { error = save_chunked(fin, tls, out, buf, buflen); @@ -1652,7 +1652,7 @@ #endif /* !SMALL */ static void -ftp_close(FILE **fin, struct tls **tls, volatile int *fd) +ftp_close(FILE **fin, struct tls **tls, int *fd) { #ifndef NOSSL int ret;