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

Kothapally Madhu Pavan posted 1 patch 6 years, 6 months ago
Failed in applying to current master (apply log)
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(-)
[libvirt] [PATCH] qemu: Move qemuFreeKeywords into qemu_parse_command.c
Posted by Kothapally Madhu Pavan 6 years, 6 months ago
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@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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: Move qemuFreeKeywords into qemu_parse_command.c
Posted by John Ferlan 6 years, 6 months ago

On 10/16/2017 04:20 PM, Kothapally Madhu Pavan wrote:
> Move qemuFreeKeywords into qemu_parse_command.c as
> qemuKeywordsFree and call it rather than inline code
> in multiple places.

To be consistent, the new API would be qemuParseKeywordsFree - API's in
qemu_parse_command.c start with qemuParse

I've fixed that up as well as this description and pushed.

Thanks for doing this quickly.

Reviewed-by: John Ferlan <jferlan@redhat.com>

(and pushed)

John

> 
> Signed-off-by: Kothapally Madhu Pavan <kmp@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(-)
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list