[PATCH 1/2] ch_driver: Avoid driver double free

Michal Privoznik mprivozn at redhat.com
Mon Jun 7 13:47:47 UTC 2021


In one of my recent patches I made chStateInitialize() return
VIR_DRV_STATE_INIT_SKIPPED if CH_CMD doesn't exist. What I did
not realize back then was that chStateCleanup() would be called
twice. This is not a problem per-se because the function is a NOP
if driver is NULL. but the problem is that at the end it calls
plain g_free(driver) which does not set driver to NULL.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/ch/ch_driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c
index 7baacd7400..374f6e5542 100644
--- a/src/ch/ch_driver.c
+++ b/src/ch/ch_driver.c
@@ -826,7 +826,7 @@ static int chStateCleanup(void)
     virObjectUnref(ch_driver->caps);
     virObjectUnref(ch_driver->config);
     virMutexDestroy(&ch_driver->lock);
-    g_free(ch_driver);
+    g_clear_pointer(&ch_driver, g_free);
 
     return 0;
 }
-- 
2.31.1




More information about the libvir-list mailing list