]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
blockdev-list: fix per-element leak in block_device_array_free() (#41869)
authorChristian Brauner <christian@amutable.com>
Wed, 29 Apr 2026 16:28:16 +0000 (18:28 +0200)
committerGitHub <noreply@github.com>
Wed, 29 Apr 2026 16:28:16 +0000 (17:28 +0100)
FOREACH_ARRAY declares 'i' as the iterator but the body passed 'd' (the
array base) to block_device_done(). Since mfree() leaves the field NULL
after the first call, element 0 is freed repeatedly while elements
1..N-1 leak their node, symlinks strv, model, vendor and subsystem.

The bug predates the sanitizer-instrumented callers. PR #41776's new
systemd-storage-block daemon runs blockdev_list() under ASan/LSan in
TEST-87-AUX-UTILS-VM and exposes it (15 allocs / 804 bytes leaked per
ListVolumes request). The fix also benefits repart and blockdev_list's
internal CLEANUP_ARRAY cleanup.

Follow-up for 9f6b2745eaa15be80568fde2a44d0a10ed6eb2a1

src/shared/blockdev-list.c

index 5b11c8169477f5b2a0e86363b15f33fc3dc43041..0efc90fd546967684aa80cf3f2a50ddc0e434142 100644 (file)
@@ -27,7 +27,7 @@ void block_device_done(BlockDevice *d) {
 void block_device_array_free(BlockDevice *d, size_t n_devices) {
 
         FOREACH_ARRAY(i, d, n_devices)
-                block_device_done(d);
+                block_device_done(i);
 
         free(d);
 }