Skip to content

Commit

Permalink
parser: remove unused list and check its size(fluent#4132)
Browse files Browse the repository at this point in the history
Signed-off-by: Takahiro Yamashita <[email protected]>
  • Loading branch information
nokute78 authored and edsiper committed Nov 2, 2021
1 parent 6307a9d commit 7e45bdd
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/flb_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,23 @@ struct flb_parser *flb_parser_create(const char *name, const char *format,
}
else {
flb_error("[parser:%s] Invalid format %s", name, format);
mk_list_del(&p->_head);
flb_free(p);
return NULL;
}

if (p->type == FLB_PARSER_REGEX) {
if (!p_regex) {
flb_error("[parser:%s] Invalid regex pattern", name);
mk_list_del(&p->_head);
flb_free(p);
return NULL;
}

regex = flb_regex_create(p_regex);
if (!regex) {
flb_error("[parser:%s] Invalid regex pattern %s", name, p_regex);
mk_list_del(&p->_head);
flb_free(p);
return NULL;
}
Expand Down Expand Up @@ -317,6 +320,7 @@ struct flb_parser *flb_parser_create(const char *name, const char *format,
void flb_parser_destroy(struct flb_parser *parser)
{
int i = 0;

if (parser->type == FLB_PARSER_REGEX) {
flb_regex_destroy(parser->regex);
flb_free(parser->p_regex);
Expand Down Expand Up @@ -867,8 +871,15 @@ struct flb_parser *flb_parser_get(const char *name, struct flb_config *config)
struct mk_list *head;
struct flb_parser *parser;

if (config == NULL || mk_list_size(&config->parsers) <= 0) {
return NULL;
}

mk_list_foreach(head, &config->parsers) {
parser = mk_list_entry(head, struct flb_parser, _head);
if (parser == NULL || parser->name == NULL) {
continue;
}
if (strcmp(parser->name, name) == 0) {
return parser;
}
Expand Down

0 comments on commit 7e45bdd

Please sign in to comment.