From 5df6d2c65e6d8aa01e7a217a7f1c957ef0cd9fab Mon Sep 17 00:00:00 2001 From: Leonardo Alminana Date: Fri, 25 Apr 2025 08:57:32 +0200 Subject: [PATCH] out_azure_blob: fixed double free Signed-off-by: Leonardo Alminana --- plugins/out_azure_blob/azure_blob.c | 30 +++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/plugins/out_azure_blob/azure_blob.c b/plugins/out_azure_blob/azure_blob.c index c13da85204d..56c9771257f 100644 --- a/plugins/out_azure_blob/azure_blob.c +++ b/plugins/out_azure_blob/azure_blob.c @@ -366,6 +366,14 @@ static int send_blob(struct flb_config *config, if (blob_type == AZURE_BLOB_APPENDBLOB) { uri = azb_append_blob_uri(ctx, tag); + + block_id = flb_sds_create_len("\0", 1); + + if (block_id == NULL) { + cfl_sds_destroy(ref_name); + + return FLB_RETRY; + } } else if (blob_type == AZURE_BLOB_BLOCKBLOB) { if (event_type == FLB_EVENT_TYPE_LOGS) { @@ -388,8 +396,12 @@ static int send_blob(struct flb_config *config, } if (!uri) { - flb_free(block_id); + if (block_id != NULL) { + flb_free(block_id); + } + flb_sds_destroy(ref_name); + return FLB_RETRY; } @@ -403,7 +415,11 @@ static int send_blob(struct flb_config *config, &payload_buf, &payload_size); if (ret != 0) { flb_sds_destroy(uri); - flb_free(block_id); + + if (block_id != NULL) { + flb_free(block_id); + } + flb_sds_destroy(ref_name); return FLB_ERROR; } @@ -420,7 +436,6 @@ static int send_blob(struct flb_config *config, /* For Logs type, we need to commit the block right away */ if (event_type == FLB_EVENT_TYPE_LOGS) { ret = azb_block_blob_commit_block(ctx, block_id, tag, ms); - flb_free(block_id); } } else if (ret == CREATE_BLOB) { @@ -436,7 +451,10 @@ static int send_blob(struct flb_config *config, } flb_sds_destroy(uri); - flb_free(block_id); + + if (block_id != NULL) { + flb_free(block_id); + } return ret; } @@ -593,13 +611,13 @@ static int ensure_container(struct flb_azure_blob *ctx) else if (status == 200) { flb_plg_info(ctx->ins, "container '%s' already exists", ctx->container_name); return FLB_TRUE; - } + } else if (status == 403) { flb_plg_error(ctx->ins, "failed getting container '%s', access denied", ctx->container_name); return FLB_FALSE; } - + flb_plg_error(ctx->ins, "get container request failed, status=%i", status);