[libvirt] [PATCH] qemu: Move qemuFreeKeywords into qemu_parse_command.c

Kothapally Madhu Pavan kmp at linux.vnet.ibm.com
Mon Oct 16 20:20:04 UTC 2017


Move qemuFreeKeywords into qemu_parse_command.c as
qemuKeywordsFree and call it rather than inline code
in multiple places.

Signed-off-by: Kothapally Madhu Pavan <kmp at linux.vnet.ibm.com>
---
 src/qemu/qemu_monitor_json.c  | 15 ++-----------
 src/qemu/qemu_parse_command.c | 52 ++++++++++++++++---------------------------
 src/qemu/qemu_parse_command.h |  5 +++++
 3 files changed, 26 insertions(+), 46 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 5546d1a..af66967 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -468,17 +468,6 @@ qemuMonitorJSONMakeCommandRaw(bool wrap, const char *cmdname, ...)
 #define qemuMonitorJSONMakeCommand(cmdname, ...) \
     qemuMonitorJSONMakeCommandRaw(false, cmdname, __VA_ARGS__)
 
-static void
-qemuFreeKeywords(int nkeywords, char **keywords, char **values)
-{
-    size_t i;
-    for (i = 0; i < nkeywords; i++) {
-        VIR_FREE(keywords[i]);
-        VIR_FREE(values[i]);
-    }
-    VIR_FREE(keywords);
-    VIR_FREE(values);
-}
 
 static virJSONValuePtr
 qemuMonitorJSONKeywordStringToJSON(const char *str, const char *firstkeyword)
@@ -513,11 +502,11 @@ qemuMonitorJSONKeywordStringToJSON(const char *str, const char *firstkeyword)
         }
     }
 
-    qemuFreeKeywords(nkeywords, keywords, values);
+    qemuKeywordsFree(nkeywords, keywords, values);
     return ret;
 
  error:
-    qemuFreeKeywords(nkeywords, keywords, values);
+    qemuKeywordsFree(nkeywords, keywords, values);
     virJSONValueFree(ret);
     return NULL;
 }
diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c
index 9f739ae..d5ea5aa 100644
--- a/src/qemu/qemu_parse_command.c
+++ b/src/qemu/qemu_parse_command.c
@@ -381,6 +381,20 @@ static const char *qemuFindEnv(char **progenv,
     return NULL;
 }
 
+
+void
+qemuKeywordsFree(int nkeywords, char **keywords, char **values)
+{
+    size_t i;
+    for (i = 0; i < nkeywords; i++) {
+        VIR_FREE(keywords[i]);
+        VIR_FREE(values[i]);
+    }
+    VIR_FREE(keywords);
+    VIR_FREE(values);
+}
+
+
 /*
  * Takes a string containing a set of key=value,key=value,key...
  * parameters and splits them up, returning two arrays with
@@ -401,7 +415,6 @@ qemuParseKeywords(const char *str,
     char **values = NULL;
     const char *start = str;
     const char *end;
-    size_t i;
 
     *retkeywords = NULL;
     *retvalues = NULL;
@@ -479,12 +492,7 @@ qemuParseKeywords(const char *str,
     return 0;
 
  error:
-    for (i = 0; i < keywordCount; i++) {
-        VIR_FREE(keywords[i]);
-        VIR_FREE(values[i]);
-    }
-    VIR_FREE(keywords);
-    VIR_FREE(values);
+    qemuKeywordsFree(keywordCount, keywords, values);
     return -1;
 }
 
@@ -949,12 +957,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
     }
 
  cleanup:
-    for (i = 0; i < nkeywords; i++) {
-        VIR_FREE(keywords[i]);
-        VIR_FREE(values[i]);
-    }
-    VIR_FREE(keywords);
-    VIR_FREE(values);
+    qemuKeywordsFree(nkeywords, keywords, values);
     return def;
 
  error:
@@ -1132,12 +1135,7 @@ qemuParseCommandLineNet(virDomainXMLOptionPtr xmlopt,
         virDomainNetGenerateMAC(xmlopt, &def->mac);
 
  cleanup:
-    for (i = 0; i < nkeywords; i++) {
-        VIR_FREE(keywords[i]);
-        VIR_FREE(values[i]);
-    }
-    VIR_FREE(keywords);
-    VIR_FREE(values);
+    qemuKeywordsFree(nkeywords, keywords, values);
     return def;
 
  error:
@@ -1704,13 +1702,7 @@ qemuParseCommandLineMem(virDomainDefPtr dom,
     ret = 0;
 
  cleanup:
-    for (i = 0; i < nkws; i++) {
-        VIR_FREE(kws[i]);
-        VIR_FREE(vals[i]);
-    }
-    VIR_FREE(kws);
-    VIR_FREE(vals);
-
+    qemuKeywordsFree(nkws, kws, vals);
     return ret;
 }
 
@@ -1795,13 +1787,7 @@ qemuParseCommandLineSmp(virDomainDefPtr dom,
     ret = 0;
 
  cleanup:
-    for (i = 0; i < nkws; i++) {
-        VIR_FREE(kws[i]);
-        VIR_FREE(vals[i]);
-    }
-    VIR_FREE(kws);
-    VIR_FREE(vals);
-
+    qemuKeywordsFree(nkws, kws, vals);
     return ret;
 
  syntax:
diff --git a/src/qemu/qemu_parse_command.h b/src/qemu/qemu_parse_command.h
index ed65342..4c553f2 100644
--- a/src/qemu/qemu_parse_command.h
+++ b/src/qemu/qemu_parse_command.h
@@ -43,6 +43,11 @@ virDomainDefPtr qemuParseCommandLinePid(virCapsPtr caps,
                                         virDomainChrSourceDefPtr *monConfig,
                                         bool *monJSON);
 
+void
+qemuKeywordsFree(int nkeywords,
+                 char **keywords,
+                 char **values);
+
 int
 qemuParseKeywords(const char *str,
                   char ***retkeywords,
-- 
2.7.4




More information about the libvir-list mailing list