summaryrefslogtreecommitdiffstats
path: root/libexec
diff options
context:
space:
mode:
authoryar <yar@FreeBSD.org>2002-08-27 09:02:52 +0000
committeryar <yar@FreeBSD.org>2002-08-27 09:02:52 +0000
commit9841ff7102fcb9adf7cbf725f1ef2d2ffda1641e (patch)
tree032f8774352b49bbc4127d4bc1ada4596b130256 /libexec
parentb2179b4b1a82c29ee2cd1467d3ae4b5958d4f18d (diff)
downloadFreeBSD-src-9841ff7102fcb9adf7cbf725f1ef2d2ffda1641e.zip
FreeBSD-src-9841ff7102fcb9adf7cbf725f1ef2d2ffda1641e.tar.gz
More inithosts() fixes:
o Don't free(3) memory occupied by host structures already in the host list. o Set hrp->hostinfo to NULL if a host record has to stay in the host list, but is to be ignored. Selecthost() knows that. o Reduce the pollution with excessive NULL checks. o Close a couple of memory leaks. MFC after: 1 week
Diffstat (limited to 'libexec')
-rw-r--r--libexec/ftpd/ftpd.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c
index 4689136..9e169d4 100644
--- a/libexec/ftpd/ftpd.c
+++ b/libexec/ftpd/ftpd.c
@@ -783,12 +783,12 @@ inithosts(void)
if ((hrp = malloc(sizeof(struct ftphost))) == NULL)
goto nextline;
hrp->hostname = NULL;
- hrp->hostinfo = NULL;
insert = 1;
- } else
+ } else {
+ if (hrp->hostinfo)
+ freeaddrinfo(hrp->hostinfo);
insert = 0; /* host already in the chain */
- if (hrp->hostinfo)
- freeaddrinfo(hrp->hostinfo);
+ }
hrp->hostinfo = res;
/*
@@ -808,9 +808,11 @@ inithosts(void)
break;
default:
/* should not reach here */
- if (hrp->hostinfo != NULL)
- freeaddrinfo(hrp->hostinfo);
- free(hrp);
+ freeaddrinfo(hrp->hostinfo);
+ if (insert)
+ free(hrp); /*not in chain, can free*/
+ else
+ hrp->hostinfo = NULL; /*mark as blank*/
goto nextline;
/* NOTREACHED */
}
@@ -836,8 +838,13 @@ inithosts(void)
hrp->hostname = NULL;
}
if (hrp->hostname == NULL &&
- (hrp->hostname = strdup(vhost)) == NULL)
+ (hrp->hostname = strdup(vhost)) == NULL) {
+ freeaddrinfo(hrp->hostinfo);
+ hrp->hostinfo = NULL; /* mark as blank */
+ if (hp)
+ freehostent(hp);
goto nextline;
+ }
hrp->anonuser = anonuser;
hrp->statfile = statfile;
hrp->welcome = welcome;
OpenPOWER on IntegriCloud