diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-01-22 14:06:03 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-01-22 14:06:03 +0000 |
commit | 0e1d6a3192da08aac94b5382fc8f738dde35a770 (patch) | |
tree | 42ddb59f35d305a5587a02197ad7630fc8ff289b /networking | |
parent | 39ec0a9d30b3fba8c8a9ab3e56492bc05d8d28d1 (diff) | |
download | busybox-w32-0e1d6a3192da08aac94b5382fc8f738dde35a770.tar.gz busybox-w32-0e1d6a3192da08aac94b5382fc8f738dde35a770.tar.bz2 busybox-w32-0e1d6a3192da08aac94b5382fc8f738dde35a770.zip |
dnsd: getfileentry was leaking memory
mount: improve readability
git-svn-id: svn://busybox.net/trunk/busybox@17460 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'networking')
-rw-r--r-- | networking/dnsd.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/networking/dnsd.c b/networking/dnsd.c index 71f50423d..6a866f1d7 100644 --- a/networking/dnsd.c +++ b/networking/dnsd.c | |||
@@ -110,7 +110,7 @@ static void undot(uint8_t * rip) | |||
110 | * Read one line of hostname/IP from file | 110 | * Read one line of hostname/IP from file |
111 | * Returns 0 for each valid entry read, -1 at EOF | 111 | * Returns 0 for each valid entry read, -1 at EOF |
112 | * Assumes all host names are lower case only | 112 | * Assumes all host names are lower case only |
113 | * Hostnames with more than one label is not handled correctly. | 113 | * Hostnames with more than one label are not handled correctly. |
114 | * Presently the dot is copied into name without | 114 | * Presently the dot is copied into name without |
115 | * converting to a length/string substring for that label. | 115 | * converting to a length/string substring for that label. |
116 | */ | 116 | */ |
@@ -118,32 +118,37 @@ static void undot(uint8_t * rip) | |||
118 | static int getfileentry(FILE * fp, struct dns_entry *s) | 118 | static int getfileentry(FILE * fp, struct dns_entry *s) |
119 | { | 119 | { |
120 | unsigned int a,b,c,d; | 120 | unsigned int a,b,c,d; |
121 | char *r, *name; | 121 | char *line, *r, *name; |
122 | 122 | ||
123 | restart: | 123 | restart: |
124 | r = xmalloc_fgets(fp); | 124 | line = r = xmalloc_fgets(fp); |
125 | if (!r) | 125 | if (!r) |
126 | return -1; | 126 | return -1; |
127 | while (*r == ' ' || *r == '\t') { | 127 | while (*r == ' ' || *r == '\t') { |
128 | r++; | 128 | r++; |
129 | if (!*r || *r == '#' || *r == '\n') | 129 | if (!*r || *r == '#' || *r == '\n') { |
130 | free(line); | ||
130 | goto restart; /* skipping empty/blank and commented lines */ | 131 | goto restart; /* skipping empty/blank and commented lines */ |
132 | } | ||
131 | } | 133 | } |
132 | name = r; | 134 | name = r; |
133 | while (*r != ' ' && *r != '\t') | 135 | while (*r != ' ' && *r != '\t') |
134 | r++; | 136 | r++; |
135 | *r++ = 0; | 137 | *r++ = '\0'; |
136 | if (sscanf(r, "%u.%u.%u.%u", &a, &b, &c, &d) != 4) | 138 | if (sscanf(r, "%u.%u.%u.%u", &a, &b, &c, &d) != 4) { |
139 | free(line); | ||
137 | goto restart; /* skipping wrong lines */ | 140 | goto restart; /* skipping wrong lines */ |
141 | } | ||
138 | 142 | ||
139 | sprintf(s->ip, "%u.%u.%u.%u", a, b, c, d); | 143 | sprintf(s->ip, "%u.%u.%u.%u", a, b, c, d); |
140 | sprintf(s->rip, ".%u.%u.%u.%u", d, c, b, a); | 144 | sprintf(s->rip, ".%u.%u.%u.%u", d, c, b, a); |
141 | undot((uint8_t*)s->rip); | 145 | undot((uint8_t*)s->rip); |
142 | convname(s->name,(uint8_t*)name); | 146 | convname(s->name, (uint8_t*)name); |
143 | 147 | ||
144 | if (OPT_verbose) | 148 | if (OPT_verbose) |
145 | fprintf(stderr, "\tname:%s, ip:%s\n", &(s->name[1]),s->ip); | 149 | fprintf(stderr, "\tname:%s, ip:%s\n", &(s->name[1]),s->ip); |
146 | 150 | ||
151 | free(line); | ||
147 | return 0; | 152 | return 0; |
148 | } | 153 | } |
149 | 154 | ||
@@ -154,14 +159,13 @@ static void dnsentryinit(void) | |||
154 | { | 159 | { |
155 | FILE *fp; | 160 | FILE *fp; |
156 | struct dns_entry *m, *prev; | 161 | struct dns_entry *m, *prev; |
157 | prev = dnsentry = NULL; | ||
158 | 162 | ||
163 | prev = dnsentry = NULL; | ||
159 | fp = xfopen(fileconf, "r"); | 164 | fp = xfopen(fileconf, "r"); |
160 | 165 | ||
161 | while (1) { | 166 | while (1) { |
162 | m = xmalloc(sizeof(struct dns_entry)); | 167 | m = xzalloc(sizeof(*m)); |
163 | 168 | /*m->next = NULL;*/ | |
164 | m->next = NULL; | ||
165 | if (getfileentry(fp, m)) | 169 | if (getfileentry(fp, m)) |
166 | break; | 170 | break; |
167 | 171 | ||