Skip to content

Commit

Permalink
config_format: cf_yaml: Cleanup variants only if occurred an exception
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 authored and edsiper committed Sep 26, 2024
1 parent 0a2dd4a commit 013837a
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/config_format/flb_cf_yaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ static int state_create_group(struct flb_cf *conf, struct parser_state *state, c
return YAML_SUCCESS;
}

static struct parser_state *state_pop(struct local_ctx *ctx)
static struct parser_state *state_pop_with_cleanup(struct local_ctx *ctx, int destroy_variants)
{
struct parser_state *last;

Expand All @@ -2083,13 +2083,15 @@ static struct parser_state *state_pop(struct local_ctx *ctx)
cfl_kvlist_destroy(last->keyvals);
}

/* Teardown associated variant stuffs */
if (last->variant_kvlist_key != NULL) {
cfl_sds_destroy(last->variant_kvlist_key);
}
if (destroy_variants == FLB_TRUE) {
/* Teardown associated variant stuffs */
if (last->variant_kvlist_key != NULL) {
cfl_sds_destroy(last->variant_kvlist_key);
}

if (last->variant != NULL) {
cfl_variant_destroy(last->variant);
if (last->variant != NULL) {
cfl_variant_destroy(last->variant);
}
}

state_destroy(last);
Expand All @@ -2101,6 +2103,11 @@ static struct parser_state *state_pop(struct local_ctx *ctx)
return cfl_list_entry_last(&ctx->states, struct parser_state, _head);
}

static struct parser_state *state_pop(struct local_ctx *ctx)
{
return state_pop_with_cleanup(ctx, FLB_FALSE);
}

static void state_destroy(struct parser_state *s)
{
flb_free(s);
Expand Down Expand Up @@ -2273,7 +2280,7 @@ static int read_config(struct flb_cf *conf, struct local_ctx *ctx,

/* free all remaining states */
if (code == -1) {
while ((state = state_pop(ctx)));
while ((state = state_pop_with_cleanup(ctx, FLB_TRUE)));
}
else {
state = state_pop(ctx);
Expand Down

0 comments on commit 013837a

Please sign in to comment.