Skip to content

Commit 5778832

Browse files
leonardo-albertovichedsiper
authored andcommitted
out_azure_blob: fixed double free
Signed-off-by: Leonardo Alminana <leonardo.alminana@chronosphere.io>
1 parent ce8afed commit 5778832

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

plugins/out_azure_blob/azure_blob.c

+24-6
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,14 @@ static int send_blob(struct flb_config *config,
366366

367367
if (blob_type == AZURE_BLOB_APPENDBLOB) {
368368
uri = azb_append_blob_uri(ctx, tag);
369+
370+
block_id = flb_sds_create_len("\0", 1);
371+
372+
if (block_id == NULL) {
373+
cfl_sds_destroy(ref_name);
374+
375+
return FLB_RETRY;
376+
}
369377
}
370378
else if (blob_type == AZURE_BLOB_BLOCKBLOB) {
371379
if (event_type == FLB_EVENT_TYPE_LOGS) {
@@ -388,8 +396,12 @@ static int send_blob(struct flb_config *config,
388396
}
389397

390398
if (!uri) {
391-
flb_free(block_id);
399+
if (block_id != NULL) {
400+
flb_free(block_id);
401+
}
402+
392403
flb_sds_destroy(ref_name);
404+
393405
return FLB_RETRY;
394406
}
395407

@@ -403,7 +415,11 @@ static int send_blob(struct flb_config *config,
403415
&payload_buf, &payload_size);
404416
if (ret != 0) {
405417
flb_sds_destroy(uri);
406-
flb_free(block_id);
418+
419+
if (block_id != NULL) {
420+
flb_free(block_id);
421+
}
422+
407423
flb_sds_destroy(ref_name);
408424
return FLB_ERROR;
409425
}
@@ -420,7 +436,6 @@ static int send_blob(struct flb_config *config,
420436
/* For Logs type, we need to commit the block right away */
421437
if (event_type == FLB_EVENT_TYPE_LOGS) {
422438
ret = azb_block_blob_commit_block(ctx, block_id, tag, ms);
423-
flb_free(block_id);
424439
}
425440
}
426441
else if (ret == CREATE_BLOB) {
@@ -436,7 +451,10 @@ static int send_blob(struct flb_config *config,
436451
}
437452

438453
flb_sds_destroy(uri);
439-
flb_free(block_id);
454+
455+
if (block_id != NULL) {
456+
flb_free(block_id);
457+
}
440458

441459
return ret;
442460
}
@@ -593,13 +611,13 @@ static int ensure_container(struct flb_azure_blob *ctx)
593611
else if (status == 200) {
594612
flb_plg_info(ctx->ins, "container '%s' already exists", ctx->container_name);
595613
return FLB_TRUE;
596-
}
614+
}
597615
else if (status == 403) {
598616
flb_plg_error(ctx->ins, "failed getting container '%s', access denied",
599617
ctx->container_name);
600618
return FLB_FALSE;
601619
}
602-
620+
603621
flb_plg_error(ctx->ins, "get container request failed, status=%i",
604622
status);
605623

0 commit comments

Comments
 (0)