From ef23c7eb382ffcb16a62e434c676b5aa5f9af92c Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Sat, 2 Mar 2024 08:05:10 +0900 Subject: [PATCH 1/2] custom_calyptia: fix using after freed memory(#8530) Signed-off-by: Takahiro Yamashita --- plugins/custom_calyptia/calyptia.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/custom_calyptia/calyptia.c b/plugins/custom_calyptia/calyptia.c index 5639af42762..351a16b0d75 100644 --- a/plugins/custom_calyptia/calyptia.c +++ b/plugins/custom_calyptia/calyptia.c @@ -245,7 +245,6 @@ static struct flb_output_instance *setup_cloud_output(struct flb_config *config, if (!cloud) { flb_plg_error(ctx->ins, "could not load Calyptia Cloud connector"); - flb_free(ctx); return NULL; } @@ -254,7 +253,6 @@ static struct flb_output_instance *setup_cloud_output(struct flb_config *config, if (ret != 0) { flb_plg_error(ctx->ins, "could not load Calyptia Cloud connector"); - flb_free(ctx); return NULL; } @@ -268,7 +266,6 @@ static struct flb_output_instance *setup_cloud_output(struct flb_config *config, label = flb_sds_create_size(strlen(key->str) + strlen(val->str) + 1); if (!label) { - flb_free(ctx); return NULL; } @@ -316,7 +313,6 @@ static struct flb_output_instance *setup_cloud_output(struct flb_config *config, label = flb_sds_create_size(strlen("fleet_id") + strlen(ctx->fleet_id) + 1); if (!label) { - flb_free(ctx); return NULL; } @@ -455,6 +451,7 @@ static int cb_calyptia_init(struct flb_custom_instance *ins, ctx->o = setup_cloud_output(config, ctx); if (ctx->o == NULL) { + flb_free(ctx); return -1; } } From b6677afdc730631951a333f7b1737891506f76f4 Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Sat, 2 Mar 2024 08:05:56 +0900 Subject: [PATCH 2/2] custom_calyptia: release ctx if init failed Signed-off-by: Takahiro Yamashita --- plugins/custom_calyptia/calyptia.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/custom_calyptia/calyptia.c b/plugins/custom_calyptia/calyptia.c index 351a16b0d75..4aba53ca79c 100644 --- a/plugins/custom_calyptia/calyptia.c +++ b/plugins/custom_calyptia/calyptia.c @@ -420,6 +420,7 @@ static int cb_calyptia_init(struct flb_custom_instance *ins, if (ctx->machine_id == NULL) { flb_plg_error(ctx->ins, "unable to retrieve machine_id"); + flb_free(ctx); return -1; } @@ -431,6 +432,7 @@ static int cb_calyptia_init(struct flb_custom_instance *ins, if (!ctx->i) { flb_plg_error(ctx->ins, "could not load metrics collector"); + flb_free(ctx); return -1; }