dnsd: getfileentry was leaking memory

mount: improve readability
This commit is contained in:
Denis Vlasenko 2007-01-22 14:06:03 +00:00
parent 35d4da0fb5
commit 6cd2d2bcba
2 changed files with 35 additions and 29 deletions

View File

@ -110,7 +110,7 @@ static void undot(uint8_t * rip)
* Read one line of hostname/IP from file * Read one line of hostname/IP from file
* Returns 0 for each valid entry read, -1 at EOF * Returns 0 for each valid entry read, -1 at EOF
* Assumes all host names are lower case only * Assumes all host names are lower case only
* Hostnames with more than one label is not handled correctly. * Hostnames with more than one label are not handled correctly.
* Presently the dot is copied into name without * Presently the dot is copied into name without
* converting to a length/string substring for that label. * converting to a length/string substring for that label.
*/ */
@ -118,32 +118,37 @@ static void undot(uint8_t * rip)
static int getfileentry(FILE * fp, struct dns_entry *s) static int getfileentry(FILE * fp, struct dns_entry *s)
{ {
unsigned int a,b,c,d; unsigned int a,b,c,d;
char *r, *name; char *line, *r, *name;
restart: restart:
r = xmalloc_fgets(fp); line = r = xmalloc_fgets(fp);
if (!r) if (!r)
return -1; return -1;
while (*r == ' ' || *r == '\t') { while (*r == ' ' || *r == '\t') {
r++; r++;
if (!*r || *r == '#' || *r == '\n') if (!*r || *r == '#' || *r == '\n') {
free(line);
goto restart; /* skipping empty/blank and commented lines */ goto restart; /* skipping empty/blank and commented lines */
}
} }
name = r; name = r;
while (*r != ' ' && *r != '\t') while (*r != ' ' && *r != '\t')
r++; r++;
*r++ = 0; *r++ = '\0';
if (sscanf(r, "%u.%u.%u.%u", &a, &b, &c, &d) != 4) if (sscanf(r, "%u.%u.%u.%u", &a, &b, &c, &d) != 4) {
free(line);
goto restart; /* skipping wrong lines */ goto restart; /* skipping wrong lines */
}
sprintf(s->ip, "%u.%u.%u.%u", a, b, c, d); sprintf(s->ip, "%u.%u.%u.%u", a, b, c, d);
sprintf(s->rip, ".%u.%u.%u.%u", d, c, b, a); sprintf(s->rip, ".%u.%u.%u.%u", d, c, b, a);
undot((uint8_t*)s->rip); undot((uint8_t*)s->rip);
convname(s->name,(uint8_t*)name); convname(s->name, (uint8_t*)name);
if (OPT_verbose) if (OPT_verbose)
fprintf(stderr, "\tname:%s, ip:%s\n", &(s->name[1]),s->ip); fprintf(stderr, "\tname:%s, ip:%s\n", &(s->name[1]),s->ip);
free(line);
return 0; return 0;
} }
@ -154,14 +159,13 @@ static void dnsentryinit(void)
{ {
FILE *fp; FILE *fp;
struct dns_entry *m, *prev; struct dns_entry *m, *prev;
prev = dnsentry = NULL;
prev = dnsentry = NULL;
fp = xfopen(fileconf, "r"); fp = xfopen(fileconf, "r");
while (1) { while (1) {
m = xmalloc(sizeof(struct dns_entry)); m = xzalloc(sizeof(*m));
/*m->next = NULL;*/
m->next = NULL;
if (getfileentry(fp, m)) if (getfileentry(fp, m))
break; break;

View File

@ -1386,14 +1386,16 @@ static int singlemount(struct mntent *mp, int ignore_busy)
// Treat fstype "auto" as unspecified. // Treat fstype "auto" as unspecified.
if (mp->mnt_type && !strcmp(mp->mnt_type,"auto")) mp->mnt_type = 0; if (mp->mnt_type && strcmp(mp->mnt_type,"auto") == 0)
mp->mnt_type = 0;
// Might this be an CIFS filesystem? // Might this be an CIFS filesystem?
if (ENABLE_FEATURE_MOUNT_CIFS && if (ENABLE_FEATURE_MOUNT_CIFS
(!mp->mnt_type || !strcmp(mp->mnt_type,"cifs")) && && (!mp->mnt_type || strcmp(mp->mnt_type,"cifs") == 0)
(mp->mnt_fsname[0]==mp->mnt_fsname[1] && (mp->mnt_fsname[0]=='/' || mp->mnt_fsname[0]=='\\'))) && (mp->mnt_fsname[0]=='/' || mp->mnt_fsname[0]=='\\')
{ && mp->mnt_fsname[0]==mp->mnt_fsname[1]
) {
struct hostent *he; struct hostent *he;
char ip[32], *s; char ip[32], *s;
@ -1407,7 +1409,7 @@ static int singlemount(struct mntent *mp, int ignore_busy)
s = strrchr(mp->mnt_fsname, '\\'); s = strrchr(mp->mnt_fsname, '\\');
if (s == mp->mnt_fsname+1) goto report_error; if (s == mp->mnt_fsname+1) goto report_error;
*s = 0; *s = '\0';
he = gethostbyname(mp->mnt_fsname+2); he = gethostbyname(mp->mnt_fsname+2);
*s = '\\'; *s = '\\';
if (!he) goto report_error; if (!he) goto report_error;
@ -1434,10 +1436,10 @@ static int singlemount(struct mntent *mp, int ignore_busy)
// Might this be an NFS filesystem? // Might this be an NFS filesystem?
if (ENABLE_FEATURE_MOUNT_NFS && if (ENABLE_FEATURE_MOUNT_NFS
(!mp->mnt_type || !strcmp(mp->mnt_type,"nfs")) && && (!mp->mnt_type || !strcmp(mp->mnt_type,"nfs"))
strchr(mp->mnt_fsname, ':') != NULL) && strchr(mp->mnt_fsname, ':') != NULL
{ ) {
rc = nfsmount(mp, vfsflags, filteropts); rc = nfsmount(mp, vfsflags, filteropts);
goto report_error; goto report_error;
} }
@ -1445,8 +1447,9 @@ static int singlemount(struct mntent *mp, int ignore_busy)
// Look at the file. (Not found isn't a failure for remount, or for // Look at the file. (Not found isn't a failure for remount, or for
// a synthetic filesystem like proc or sysfs.) // a synthetic filesystem like proc or sysfs.)
if (!lstat(mp->mnt_fsname, &st) && !(vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE))) if (!lstat(mp->mnt_fsname, &st)
{ && !(vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE))
) {
// Do we need to allocate a loopback device for it? // Do we need to allocate a loopback device for it?
if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) { if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) {
@ -1474,10 +1477,9 @@ static int singlemount(struct mntent *mp, int ignore_busy)
if (mp->mnt_type || (vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE))) if (mp->mnt_type || (vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE)))
rc = mount_it_now(mp, vfsflags, filteropts); rc = mount_it_now(mp, vfsflags, filteropts);
// Loop through filesystem types until mount succeeds or we run out
else { else {
// Loop through filesystem types until mount succeeds
// or we run out
/* Initialize list of block backed filesystems. This has to be /* Initialize list of block backed filesystems. This has to be
* done here so that during "mount -a", mounts after /proc shows up * done here so that during "mount -a", mounts after /proc shows up
@ -1612,9 +1614,9 @@ int mount_main(int argc, char **argv)
// If we have a shared subtree flag, don't worry about fstab or mtab. // If we have a shared subtree flag, don't worry about fstab or mtab.
if (ENABLE_FEATURE_MOUNT_FLAGS && if (ENABLE_FEATURE_MOUNT_FLAGS
(i & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))) && (i & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
{ ) {
rc = mount("", argv[0], "", i, ""); rc = mount("", argv[0], "", i, "");
if (rc) bb_perror_msg_and_die("%s", argv[0]); if (rc) bb_perror_msg_and_die("%s", argv[0]);
goto clean_up; goto clean_up;