mirror of
https://github.com/topjohnwu/ndk-busybox.git
synced 2024-12-13 23:08:53 +00:00
universal parser: do not leak parser->data
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
1fcbff2fac
commit
63144be7ea
@ -128,8 +128,8 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const
|
|||||||
int ntokens, mintokens;
|
int ntokens, mintokens;
|
||||||
int t, len;
|
int t, len;
|
||||||
|
|
||||||
ntokens = flags & 0xFF;
|
ntokens = (uint8_t)flags;
|
||||||
mintokens = (flags & 0xFF00) >> 8;
|
mintokens = (uint8_t)(flags >> 8);
|
||||||
|
|
||||||
if (parser == NULL)
|
if (parser == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
@ -159,7 +159,8 @@ again:
|
|||||||
parser->data = xstrdup(line);
|
parser->data = xstrdup(line);
|
||||||
|
|
||||||
/* Tokenize the line */
|
/* Tokenize the line */
|
||||||
for (t = 0; *line && *line != delims[0] && t < ntokens; t++) {
|
t = 0;
|
||||||
|
do {
|
||||||
/* Pin token */
|
/* Pin token */
|
||||||
tokens[t] = line;
|
tokens[t] = line;
|
||||||
|
|
||||||
@ -179,10 +180,10 @@ again:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Token not terminated? */
|
/* Token not terminated? */
|
||||||
if (line[0] == delims[0])
|
if (*line == delims[0])
|
||||||
*line = '\0';
|
*line = '\0';
|
||||||
else if (line[0] != '\0')
|
else if (*line != '\0')
|
||||||
*(line++) = '\0';
|
*line++ = '\0';
|
||||||
|
|
||||||
#if 0 /* unused so far */
|
#if 0 /* unused so far */
|
||||||
if (flags & PARSE_ESCAPE) {
|
if (flags & PARSE_ESCAPE) {
|
||||||
@ -201,17 +202,20 @@ again:
|
|||||||
*to = '\0';
|
*to = '\0';
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Skip possible delimiters */
|
/* Skip possible delimiters */
|
||||||
if (flags & PARSE_COLLAPSE)
|
if (flags & PARSE_COLLAPSE)
|
||||||
line += strspn(line, delims + 1);
|
line += strspn(line, delims + 1);
|
||||||
}
|
|
||||||
|
t++;
|
||||||
|
} while (*line && *line != delims[0] && t < ntokens);
|
||||||
|
|
||||||
if (t < mintokens) {
|
if (t < mintokens) {
|
||||||
bb_error_msg("bad line %u: %d tokens found, %d needed",
|
bb_error_msg("bad line %u: %d tokens found, %d needed",
|
||||||
parser->lineno, t, mintokens);
|
parser->lineno, t, mintokens);
|
||||||
if (flags & PARSE_MIN_DIE)
|
if (flags & PARSE_MIN_DIE)
|
||||||
xfunc_die();
|
xfunc_die();
|
||||||
|
if (flags & PARSE_KEEP_COPY)
|
||||||
|
free(parser->data);
|
||||||
goto again;
|
goto again;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user