From 013837a04ccc146b416b8bfd20f29720bbed483b Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Thu, 26 Sep 2024 19:07:53 +0900 Subject: [PATCH] config_format: cf_yaml: Cleanup variants only if occurred an exception Signed-off-by: Hiroshi Hatake --- src/config_format/flb_cf_yaml.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/config_format/flb_cf_yaml.c b/src/config_format/flb_cf_yaml.c index c7c88ae5e8d..e09034393f3 100644 --- a/src/config_format/flb_cf_yaml.c +++ b/src/config_format/flb_cf_yaml.c @@ -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; @@ -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); @@ -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); @@ -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);