[libvirt] [PATCH] qemu: fix lastError memory leak

Wangyufei (James) james.wangyufei at huawei.com
Mon Dec 2 13:25:12 UTC 2013


When an error occurred in qemuMonitorIO, it will be saved in mon->lastError,
but the memory which mon->lastError.message, mon->lastError.str1,
mon->lastError.str2 and mon->lastError.str3 will not be freed at last.
The same bug happened in qemuAgentIO. So I add the following code to fix it.

Signed-off-by: Zhou Yimin <zhouyimin at huawei.com>
---
 src/qemu/qemu_agent.c   |    2 ++
 src/qemu/qemu_monitor.c |    2 ++
 2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 2cd0ccc..475b43e 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -161,6 +161,8 @@ static void qemuAgentDispose(void *obj)
         (mon->cb->destroy)(mon, mon->vm);
     virCondDestroy(&mon->notify);
     VIR_FREE(mon->buffer);
+    if (mon->lastError.code != VIR_ERR_OK)
+        virResetError(&mon->lastError);
 }
 
 static int
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 1514715..df72c5d 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -263,6 +263,8 @@ static void qemuMonitorDispose(void *obj)
     virJSONValueFree(mon->options);
     VIR_FREE(mon->balloonpath);
     VIR_FORCE_CLOSE(mon->logfd);
+    if (mon->lastError.code != VIR_ERR_OK)
+        virResetError(&mon->lastError);
 }
 
 
-- 
1.7.3.1.msysgit.0

Best Regards,
-WangYufei





More information about the libvir-list mailing list