From 9594a76755fd2a6f8cb1aba53acee335813f8af5 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Sun, 14 Jan 2024 08:51:21 -0800 Subject: [PATCH] hdr_historgram_log: fix 3 memory leaks on histogram-counts The fuzzer from https://github.com/HdrHistogram/HdrHistogram_c/pull/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 --- src/hdr_histogram_log.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hdr_histogram_log.c b/src/hdr_histogram_log.c index aebe2ec..39fb96b 100644 --- a/src/hdr_histogram_log.c +++ b/src/hdr_histogram_log.c @@ -442,7 +442,7 @@ static int hdr_decode_compressed_v0( if (result != 0) { - hdr_free(h); + hdr_close(h); } else if (NULL == *histogram) { @@ -547,7 +547,7 @@ static int hdr_decode_compressed_v1( if (result != 0) { - hdr_free(h); + hdr_close(h); } else if (NULL == *histogram) { @@ -649,7 +649,7 @@ static int hdr_decode_compressed_v2( if (result != 0) { - hdr_free(h); + hdr_close(h); } else if (NULL == *histogram) {