]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ch: Avoid memleak in virCHDriverConfigDispose()
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 9 Sep 2025 15:10:56 +0000 (17:10 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 10 Sep 2025 07:56:50 +0000 (09:56 +0200)
When virCHDriverConfig struct is initialized in
virCHDriverConfigNew() the 'configDir' member is allocated but
corresponding free is missing in virCHDriverConfigDispose().
While at it, reorder the free calls to match the order in which
they are declared in the struct so it's easier to spot missing
free call.

20 bytes in 1 blocks are definitely lost in loss record 667 of 2,033
   at 0x4912888: malloc (vg_replace_malloc.c:446)
   by 0x5436747: __vasprintf_internal (in /usr/lib64/libc.so.6)
   by 0x503EC81: g_vasprintf (in /usr/lib64/libglib-2.0.so.0.8400.3)
   by 0x500805B: g_strdup_vprintf (in /usr/lib64/libglib-2.0.so.0.8400.3)
   by 0x5008124: g_strdup_printf (in /usr/lib64/libglib-2.0.so.0.8400.3)
   by 0xB8C2B70: virCHDriverConfigNew (ch_conf.c:181)
   by 0xB8C9DDA: chStateInitialize (ch_driver.c:1456)
   by 0x4D9E316: virStateInitialize (libvirt.c:667)
   by 0x40539DB: daemonRunStateInit (remote_daemon.c:581)
   by 0x4AC1EB4: virThreadHelper (virthread.c:256)
   by 0x5441DE3: start_thread (in /usr/lib64/libc.so.6)
   by 0x54C25F3: clone (in /usr/lib64/libc.so.6)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/ch/ch_conf.c

index b9432e2a421d1ac1a148f1b9b68d13ae2bd8ae13..8a542eef19f4d4fa523ef4af3171d2cd74478220 100644 (file)
@@ -211,9 +211,10 @@ virCHDriverConfigDispose(void *obj)
 {
     virCHDriverConfig *cfg = obj;
 
-    g_free(cfg->saveDir);
     g_free(cfg->stateDir);
+    g_free(cfg->configDir);
     g_free(cfg->logDir);
+    g_free(cfg->saveDir);
 }
 
 #define MIN_VERSION ((15 * 1000000) + (0 * 1000) + (0))