diff --git a/plugins/out_s3/s3.c b/plugins/out_s3/s3.c index b486a435b4d..36db7a4a4ec 100644 --- a/plugins/out_s3/s3.c +++ b/plugins/out_s3/s3.c @@ -1564,7 +1564,7 @@ static int add_to_queue(struct flb_s3 *ctx, struct s3_file *upload_file, struct multipart_upload *m_upload_file, const char *tag, int tag_len) { struct upload_queue *upload_contents; - char *tag_cpy; + flb_sds_t tag_cpy; /* Create upload contents object and add to upload queue */ upload_contents = flb_malloc(sizeof(struct upload_queue)); @@ -1580,16 +1580,15 @@ static int add_to_queue(struct flb_s3 *ctx, struct s3_file *upload_file, upload_contents->upload_time = -1; /* Necessary to create separate string for tag to prevent corruption */ - tag_cpy = flb_malloc(tag_len); - if (tag_cpy == NULL) { - flb_free(upload_contents); - flb_plg_error(ctx->ins, "Error allocating memory for tag in add_to_queue"); + tag_cpy = flb_sds_create_len(tag, tag_len); + if (!tag_cpy) { flb_errno(); + flb_free(upload_contents); return -1; } - strncpy(tag_cpy, tag, tag_len); upload_contents->tag = tag_cpy; + /* Add entry to upload queue */ mk_list_add(&upload_contents->_head, &ctx->upload_queue); return 0; @@ -1599,7 +1598,7 @@ static int add_to_queue(struct flb_s3 *ctx, struct s3_file *upload_file, void remove_from_queue(struct upload_queue *entry) { mk_list_del(&entry->_head); - flb_free(entry->tag); + flb_sds_destroy(entry->tag); flb_free(entry); return; } diff --git a/plugins/out_s3/s3.h b/plugins/out_s3/s3.h index 3be84823eee..0f60aa90f0e 100644 --- a/plugins/out_s3/s3.h +++ b/plugins/out_s3/s3.h @@ -61,7 +61,7 @@ struct upload_queue { struct s3_file *upload_file; struct multipart_upload *m_upload_file; - char *tag; + flb_sds_t tag; int tag_len; int retry_counter;