Skip to contentSkip to conversation

block: fix leak of block histogram data

PATCH Superseded Daniel P. Berrangé 3 participants 4 messages Oct 12 – Oct 30 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: fix leak of block histogram data

The block_acct_cleanup method failed to release memory associated with block histograms.

Fixes b741ae7417 (block/accounting: introduce latency histogram)
---
 block/accounting.c | 7 +++++++
 1 file changed, 7 insertions(+)
block/accounting.c +7 -0
index 038af370170..40ed70782b4 100644
@@ -80,6 +80,13 @@ bool block_acct_setup(BlockAcctStats *stats, enum OnOffAuto account_invalid,
 void block_acct_cleanup(BlockAcctStats *stats)
 {
     BlockAcctTimedStats *s, *next;
+    size_t i;
+    for (i = 0; i < BLOCK_MAX_IOTYPE; i++) {
+        BlockLatencyHistogram *hist = &stats->latency_histogram[i];
+        g_free(hist->bins);
+        g_free(hist->boundaries);
+    }
+
     QSLIST_FOREACH_SAFE(s, &stats->intervals, entries, next) {
         g_free(s);
     }
Signature · 1 line
2.56.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Daniel P. Berrangé

The block_acct_cleanup method failed to release memory associated with block histograms.

Fixes b741ae7417 (block/accounting: introduce latency histogram)
---
 block/accounting.c | 7 +++++++
 1 file changed, 7 insertions(+)
Quoted 23 lines
block/accounting.c +7 -0
index 038af370170..40ed70782b4 100644
@@ -80,6 +80,13 @@ bool block_acct_setup(BlockAcctStats *stats, enum OnOffAuto account_invalid,
 void block_acct_cleanup(BlockAcctStats *stats)
 {
     BlockAcctTimedStats *s, *next;
+    size_t i;
+    for (i = 0; i < BLOCK_MAX_IOTYPE; i++) {
+        BlockLatencyHistogram *hist = &stats->latency_histogram[i];
+        g_free(hist->bins);
+        g_free(hist->boundaries);
+    }
+
     QSLIST_FOREACH_SAFE(s, &stats->intervals, entries, next) {
         g_free(s);
     }
Signature · 1 line
2.56.0
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org
#2 lore raw
In reply to Daniel P. Berrangé

Am 12.10.2026 um 13:43 hat Daniel P. Berrangé geschrieben:

Quoted 14 lines

The block_acct_cleanup method failed to release memory associated with block histograms.

Fixes b741ae7417 (block/accounting: introduce latency histogram)
---
 block/accounting.c | 7 +++++++
 1 file changed, 7 insertions(+)
block/accounting.c +0 -0
index 038af370170..40ed70782b4 100644

block/accounting.c bool block_acct_setup(BlockAcctStats *stats, enum OnOffAuto account_invalid, · line 89

Quoted 10 lines
block/accounting.c +7 -0
@@ -80,6 +80,13 @@ bool block_acct_setup(BlockAcctStats *stats, enum OnOffAuto account_invalid,
 void block_acct_cleanup(BlockAcctStats *stats)
 {
     BlockAcctTimedStats *s, *next;
+    size_t i;
+    for (i = 0; i < BLOCK_MAX_IOTYPE; i++) {
+        BlockLatencyHistogram *hist = &stats->latency_histogram[i];
+        g_free(hist->bins);
+        g_free(hist->boundaries);
+    }
+

This seems to duplicate block_latency_histograms_clear(). Should we just call it here?

Kevin

#3 lore raw
Quoted 20 lines · Kevin Wolf

Am 12.10.2026 um 13:43 hat Daniel P. Berrangé geschrieben:

Quoted 19 lines

The block_acct_cleanup method failed to release memory associated with block histograms.

Fixes b741ae7417 (block/accounting: introduce latency histogram)
---
 block/accounting.c | 7 +++++++
 1 file changed, 7 insertions(+)
block/accounting.c +2 -0
index 038af370170..40ed70782b4 100644
@@ -80,6 +80,13 @@ bool block_acct_setup(BlockAcctStats *stats, enum OnOffAuto account_invalid,
 void block_acct_cleanup(BlockAcctStats *stats)
 {
     BlockAcctTimedStats *s, *next;
+    size_t i;
+    for (i = 0; i < BLOCK_MAX_IOTYPE; i++) {
Quoted 8 lines

block/accounting.c bool block_acct_setup(BlockAcctStats *stats, enum OnOffAuto account_invalid, · line 89

Quoted 5 lines
block/accounting.c +5 -0
+        BlockLatencyHistogram *hist = &stats->latency_histogram[i];
+        g_free(hist->bins);
+        g_free(hist->boundaries);
+    }
+

This seems to duplicate block_latency_histograms_clear(). Should we just call it here?

Yes, that sounds sensible, I'll repost.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|