Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decode_prometheus: fixed constant pointer release #219

Merged
merged 6 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/cmt_decode_prometheus.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,16 @@ static void reset_context(struct cmt_decode_prometheus_context *context,
}

if (context->metric.ns) {
if (strcmp(context->metric.ns, "")) {
if ((void *) context->metric.ns != (void *) "") {
/* when namespace is empty, "name" contains a pointer to the
* allocated string */
* allocated string.
*
* Note : When the metric name doesn't include the namespace
* ns is set to a constant empty string and we need to
* differentiate that case from the case where an empty
* namespace is provided.
*/

free(context->metric.ns);
}
else {
Expand Down Expand Up @@ -516,7 +523,7 @@ static int add_metric_histogram(struct cmt_decode_prometheus_context *context)
"failed to parse bucket");
goto end;
}
if (parse_uint64(sample->value1,
if (parse_uint64(sample->value1,
bucket_defaults + bucket_index)) {
/* Count is supposed to be integer, but apparently
* some tools can generate count in a floating format.
Expand Down
5 changes: 4 additions & 1 deletion tests/prometheus_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1678,13 +1678,16 @@ void test_issue_fluent_bit_9267()
cfl_sds_t in_buf = read_file(CMT_TESTS_DATA_PATH "/issue_fluent_bit_9267.txt");
size_t in_size = cfl_sds_len(in_buf);

cmt = NULL;
status = cmt_decode_prometheus_create(&cmt, in_buf, in_size, &opts);
TEST_CHECK(status == 0);
if (status) {
fprintf(stderr, "PARSE ERROR:\n======\n%s\n======\n", errbuf);
}

cmt_decode_prometheus_destroy(cmt);
if (cmt != NULL) {
cmt_decode_prometheus_destroy(cmt);
}
cfl_sds_destroy(in_buf);
}

Expand Down
Loading