From 62471bc413669c2f54b41801372b125e01d5221c Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Sun, 24 Sep 2023 08:27:52 +0900 Subject: [PATCH 1/4] out_oracle_log_analytics: remove flb_errno that checks NULL Signed-off-by: Takahiro Yamashita --- plugins/out_oracle_log_analytics/oci_logan_conf.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/plugins/out_oracle_log_analytics/oci_logan_conf.c b/plugins/out_oracle_log_analytics/oci_logan_conf.c index a3980318465..608727abec3 100644 --- a/plugins/out_oracle_log_analytics/oci_logan_conf.c +++ b/plugins/out_oracle_log_analytics/oci_logan_conf.c @@ -290,7 +290,6 @@ struct flb_oci_logan *flb_oci_logan_conf_create(struct flb_output_instance *ins, if (ctx->oci_config_in_record == FLB_FALSE) { if (ctx->oci_la_log_source_name == NULL || ctx->oci_la_log_group_id == NULL) { - flb_errno(); flb_plg_error(ctx->ins, "log source name and log group id are required"); flb_oci_logan_conf_destroy(ctx); @@ -318,7 +317,6 @@ struct flb_oci_logan *flb_oci_logan_conf_create(struct flb_output_instance *ins, } if (!ctx->config_file_location) { - flb_errno(); flb_plg_error(ctx->ins, "config file location is required"); flb_oci_logan_conf_destroy(ctx); return NULL; @@ -336,7 +334,6 @@ struct flb_oci_logan *flb_oci_logan_conf_create(struct flb_output_instance *ins, } else { if (!ctx->region) { - flb_errno(); flb_plg_error(ctx->ins, "Region is required"); flb_oci_logan_conf_destroy(ctx); return NULL; @@ -347,7 +344,6 @@ struct flb_oci_logan *flb_oci_logan_conf_create(struct flb_output_instance *ins, if (!ctx->uri) { if (!ctx->namespace) { - flb_errno(); flb_plg_error(ctx->ins, "Namespace is required"); flb_oci_logan_conf_destroy(ctx); return NULL; @@ -490,4 +486,4 @@ int flb_oci_logan_conf_destroy(struct flb_oci_logan *ctx) { flb_free(ctx); return 0; -} \ No newline at end of file +} From eb127a3511d65a1267a8746fe08f89750f5af1d2 Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Sun, 24 Sep 2023 08:30:06 +0900 Subject: [PATCH 2/4] out_oracle_log_analytics: add flb_sds_destroy for key Signed-off-by: Takahiro Yamashita --- plugins/out_oracle_log_analytics/oci_logan_conf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/out_oracle_log_analytics/oci_logan_conf.c b/plugins/out_oracle_log_analytics/oci_logan_conf.c index 608727abec3..9fb061faff4 100644 --- a/plugins/out_oracle_log_analytics/oci_logan_conf.c +++ b/plugins/out_oracle_log_analytics/oci_logan_conf.c @@ -209,6 +209,7 @@ static int global_metadata_fields_create(struct flb_oci_logan *ctx) } f->val = flb_sds_create(val->str); if (!f->val) { + flb_sds_destroy(f->key); flb_free(f); return -1; } @@ -249,6 +250,7 @@ static int log_event_metadata_create(struct flb_oci_logan *ctx) } f->val = flb_sds_create(val->str); if (!f->val) { + flb_sds_destroy(f->key); flb_free(f); return -1; } From ba44efd4105aa99b556f4ae716554596e2f27f96 Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Sun, 24 Sep 2023 09:01:14 +0900 Subject: [PATCH 3/4] out_oracle_log_analytics: fix mk_list cleanup function Signed-off-by: Takahiro Yamashita --- .../out_oracle_log_analytics/oci_logan_conf.c | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/plugins/out_oracle_log_analytics/oci_logan_conf.c b/plugins/out_oracle_log_analytics/oci_logan_conf.c index 9fb061faff4..87a34aab681 100644 --- a/plugins/out_oracle_log_analytics/oci_logan_conf.c +++ b/plugins/out_oracle_log_analytics/oci_logan_conf.c @@ -279,6 +279,8 @@ struct flb_oci_logan *flb_oci_logan_conf_create(struct flb_output_instance *ins, flb_errno(); return NULL; } + mk_list_init(&ctx->global_metadata_fields); + mk_list_init(&ctx->log_event_metadata_fields); ctx->ins = ins; @@ -298,8 +300,8 @@ struct flb_oci_logan *flb_oci_logan_conf_create(struct flb_output_instance *ins, return NULL; } } + if (ctx->oci_la_global_metadata != NULL) { - mk_list_init(&ctx->global_metadata_fields); ret = global_metadata_fields_create(ctx); if (ret != 0) { flb_errno(); @@ -309,7 +311,6 @@ struct flb_oci_logan *flb_oci_logan_conf_create(struct flb_output_instance *ins, } if (ctx->oci_la_metadata != NULL) { - mk_list_init(&ctx->log_event_metadata_fields); ret = log_event_metadata_create(ctx); if (ret != 0) { flb_errno(); @@ -435,16 +436,24 @@ static void metadata_fields_destroy(struct flb_oci_logan *ctx) mk_list_foreach_safe(head, tmp, &ctx->global_metadata_fields) { f = mk_list_entry(head, struct metadata_obj, _head); - flb_sds_destroy(f->key); - flb_sds_destroy(f->val); + if (f->key) { + flb_sds_destroy(f->key); + } + if (f->val) { + flb_sds_destroy(f->val); + } mk_list_del(&f->_head); flb_free(f); } mk_list_foreach_safe(head, tmp, &ctx->log_event_metadata_fields) { f = mk_list_entry(head, struct metadata_obj, _head); - flb_sds_destroy(f->key); - flb_sds_destroy(f->val); + if (f->key) { + flb_sds_destroy(f->key); + } + if (f->val) { + flb_sds_destroy(f->val); + } mk_list_del(&f->_head); flb_free(f); } From 9a1d4f242973f89091e783b901fd6ed0bbe355b2 Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Sun, 24 Sep 2023 09:10:50 +0900 Subject: [PATCH 4/4] out_oracle_log_analytics: set NULL to prevent double free Signed-off-by: Takahiro Yamashita --- plugins/out_oracle_log_analytics/oci_logan_conf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/out_oracle_log_analytics/oci_logan_conf.c b/plugins/out_oracle_log_analytics/oci_logan_conf.c index 87a34aab681..cc1a73cceec 100644 --- a/plugins/out_oracle_log_analytics/oci_logan_conf.c +++ b/plugins/out_oracle_log_analytics/oci_logan_conf.c @@ -121,6 +121,7 @@ static int load_oci_credentials(struct flb_oci_logan *ctx) goto iterate; } mk_mem_free(profile); + profile = NULL; } if(found_profile) { if(line[0] == '[') {