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

hdr_historgram_log: fix 3 memory leaks on histogram-counts #122

Merged
merged 1 commit into from
Jan 15, 2024

Conversation

DavidKorczynski
Copy link
Contributor

The fuzzer from #120 found some leaks when the hdr_decode_compressed* functions call hdr_init but later fails and cleans up h by way of hdr_free(h). The problem is that the counts field on the histogram is leaked, which is allocated here:

counts = (int64_t*) hdr_calloc((size_t) cfg.counts_len, sizeof(int64_t));
and assigned to the counts field here:
histogram->counts = counts;

Instead of using hdr_free the cleanup function should be `hdr_close:

void hdr_close(struct hdr_histogram* h)
{
if (h) {
hdr_free(h->counts);
hdr_free(h);
}
}

The fuzzer from HdrHistogram#120
found some leaks when the `hdr_decode_compressed*` functions call
`hdr_init` but later fails and cleans up `h` by way of `hdr_free(h)`.
The problem is that the `counts` field on the histogram is leaked, which
is allocated
https://github.com/HdrHistogram/HdrHistogram_c/blob/8dcce8f68512fca460b171bccc3a5afce0048779/src/hdr_histogram.c#L424
and assigned to the `counts` field here:
https://github.com/HdrHistogram/HdrHistogram_c/blob/8dcce8f68512fca460b171bccc3a5afce0048779/src/hdr_histogram.c#L437

Signed-off-by: David Korczynski <david@adalogics.com>
@mikeb01 mikeb01 merged commit 9594a76 into HdrHistogram:main Jan 15, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants