[libvirt] [PATCH 1/2] qemu: More qemu_monitor_json cleanups

John Ferlan jferlan at redhat.com
Mon May 16 14:05:04 UTC 2016


Recent adjustments to the code produced a litany of coverity false
positives, but only because the "standard" procedure of setting a
variable to NULL after it was assigned to something else and keeping
the *Free/*FREE call in the cleanup path wasn't kept. So this patch
makes those adjustments (assign variable to NULL and remove the if
'ret < 0' condition to clean it up).

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/qemu/qemu_monitor_json.c | 46 ++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 4cf8d75..1790e4d 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -4863,9 +4863,10 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon,
 
     ret = n;
     *machines = infolist;
+    infolist = NULL;
 
  cleanup:
-    if (ret < 0 && infolist) {
+    if (infolist) {
         for (i = 0; i < n; i++)
             qemuMonitorMachineInfoFree(infolist[i]);
         VIR_FREE(infolist);
@@ -4939,10 +4940,10 @@ int qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
 
     ret = n;
     *cpus = cpulist;
+    cpulist = NULL;
 
  cleanup:
-    if (ret < 0)
-        virStringFreeList(cpulist);
+    virStringFreeList(cpulist);
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
     return ret;
@@ -5003,10 +5004,11 @@ int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
 
     ret = n;
     *commands = commandlist;
+    commandlist = NULL;
+
 
  cleanup:
-    if (ret < 0)
-        virStringFreeList(commandlist);
+    virStringFreeList(commandlist);
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
     return ret;
@@ -5072,10 +5074,10 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon,
 
     ret = n;
     *events = eventlist;
+    eventlist = NULL;
 
  cleanup:
-    if (ret < 0)
-        virStringFreeList(eventlist);
+    virStringFreeList(eventlist);
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
     return ret;
@@ -5189,6 +5191,7 @@ qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon,
 
     ret = n;
     *params = paramlist;
+    paramlist = NULL;
 
  cleanup:
     /* If we failed before getting the JSON array of options, we (try)
@@ -5196,8 +5199,7 @@ qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon,
     if (!qemuMonitorGetOptions(mon))
         qemuMonitorSetOptions(mon, virJSONValueNewArray());
 
-    if (ret < 0)
-        virStringFreeList(paramlist);
+    virStringFreeList(paramlist);
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
     return ret;
@@ -5306,10 +5308,10 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon,
 
     ret = n;
     *types = typelist;
+    typelist = NULL;
 
  cleanup:
-    if (ret < 0)
-        virStringFreeList(typelist);
+    virStringFreeList(typelist);
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
     return ret;
@@ -5389,9 +5391,10 @@ int qemuMonitorJSONGetObjectListPaths(qemuMonitorPtr mon,
 
     ret = n;
     *paths = pathlist;
+    pathlist = NULL;
 
  cleanup:
-    if (ret < 0 && pathlist) {
+    if (pathlist) {
         for (i = 0; i < n; i++)
             qemuMonitorJSONListPathFree(pathlist[i]);
         VIR_FREE(pathlist);
@@ -5616,10 +5619,10 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
 
     ret = n;
     *props = proplist;
+    proplist = NULL;
 
  cleanup:
-    if (ret < 0)
-        virStringFreeList(proplist);
+    virStringFreeList(proplist);
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
     return ret;
@@ -5726,10 +5729,10 @@ qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr mon,
 
     ret = n;
     *capabilities = list;
+    list = NULL;
 
  cleanup:
-    if (ret < 0)
-        virStringFreeList(list);
+    virStringFreeList(list);
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
     return ret;
@@ -5911,10 +5914,10 @@ qemuMonitorJSONGetGICCapabilities(qemuMonitorPtr mon,
 
     ret = n;
     *capabilities = list;
+    list = NULL;
 
  cleanup:
-    if (ret < 0)
-        VIR_FREE(list);
+    VIR_FREE(list);
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
 
@@ -6125,10 +6128,10 @@ qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd,
 
     ret = n;
     *array = list;
+    list = NULL;
 
  cleanup:
-    if (ret < 0)
-        virStringFreeList(list);
+    virStringFreeList(list);
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
     return ret;
@@ -6668,9 +6671,10 @@ qemuMonitorJSONGetIOThreads(qemuMonitorPtr mon,
 
     ret = n;
     *iothreads = infolist;
+    infolist = NULL;
 
  cleanup:
-    if (ret < 0 && infolist) {
+    if (infolist) {
         for (i = 0; i < n; i++)
             VIR_FREE(infolist[i]);
         VIR_FREE(infolist);
-- 
2.5.5




More information about the libvir-list mailing list