Skip to content

Commit 795032e

Browse files
jinyongchoiedsiper
authored andcommitted
input_chunk: routes_mask is not initialized (#10223)
This patch fixes an issue where routes_mask was not initialized, leading to potential errors, by adding the necessary initialization code. Signed-off-by: jinyong.choi <[email protected]>
1 parent ebc19e6 commit 795032e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/flb_input_chunk.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,17 @@ struct flb_input_chunk *flb_input_chunk_map(struct flb_input_instance *in,
640640
return NULL;
641641
}
642642

643+
ic->routes_mask = (flb_route_mask_element *)
644+
flb_calloc(in->config->route_mask_size,
645+
sizeof(flb_route_mask_element));
646+
647+
if (ic->routes_mask == NULL) {
648+
flb_errno();
649+
cio_chunk_close(chunk, CIO_TRUE);
650+
flb_free(ic);
651+
return NULL;
652+
}
653+
643654
if (ic->event_type == FLB_INPUT_LOGS) {
644655
/* Validate records in the chunk */
645656
ret = flb_mp_validate_log_chunk(buf_data, buf_size, &records, &offset);
@@ -649,6 +660,7 @@ struct flb_input_chunk *flb_input_chunk_map(struct flb_input_instance *in,
649660
flb_plg_error(in,
650661
"chunk validation failed, data might be corrupted. "
651662
"No valid records found, the chunk will be discarded.");
663+
flb_free(ic->routes_mask);
652664
flb_free(ic);
653665
return NULL;
654666
}
@@ -668,6 +680,7 @@ struct flb_input_chunk *flb_input_chunk_map(struct flb_input_instance *in,
668680
"Found %d valid records, failed content starts "
669681
"right after byte %lu. Cannot recover chunk,",
670682
records, offset);
683+
flb_free(ic->routes_mask);
671684
flb_free(ic);
672685
return NULL;
673686
}
@@ -680,6 +693,7 @@ struct flb_input_chunk *flb_input_chunk_map(struct flb_input_instance *in,
680693
flb_plg_error(in,
681694
"metrics chunk validation failed, data might be corrupted. "
682695
"No valid records found, the chunk will be discarded.");
696+
flb_free(ic->routes_mask);
683697
flb_free(ic);
684698
return NULL;
685699
}
@@ -699,6 +713,7 @@ struct flb_input_chunk *flb_input_chunk_map(struct flb_input_instance *in,
699713
"Found %d valid records, failed content starts "
700714
"right after byte %lu. Cannot recover chunk,",
701715
records, offset);
716+
flb_free(ic->routes_mask);
702717
flb_free(ic);
703718
return NULL;
704719
}
@@ -714,6 +729,7 @@ struct flb_input_chunk *flb_input_chunk_map(struct flb_input_instance *in,
714729
flb_plg_error(in,
715730
"chunk validation failed, data might be corrupted. "
716731
"No valid records found, the chunk will be discarded.");
732+
flb_free(ic->routes_mask);
717733
flb_free(ic);
718734
return NULL;
719735
}
@@ -724,6 +740,7 @@ struct flb_input_chunk *flb_input_chunk_map(struct flb_input_instance *in,
724740
*/
725741
bytes = cio_chunk_get_content_size(chunk);
726742
if (bytes == -1) {
743+
flb_free(ic->routes_mask);
727744
flb_free(ic);
728745
return NULL;
729746
}
@@ -756,13 +773,15 @@ struct flb_input_chunk *flb_input_chunk_map(struct flb_input_instance *in,
756773
ret = flb_input_chunk_get_tag(ic, &tag_buf, &tag_len);
757774
if (ret == -1) {
758775
flb_error("[input chunk] error retrieving tag of input chunk");
776+
flb_free(ic->routes_mask);
759777
flb_free(ic);
760778
return NULL;
761779
}
762780

763781
bytes = flb_input_chunk_get_real_size(ic);
764782
if (bytes < 0) {
765783
flb_warn("[input chunk] could not retrieve chunk real size");
784+
flb_free(ic->routes_mask);
766785
flb_free(ic);
767786
return NULL;
768787
}

0 commit comments

Comments
 (0)