]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Move qemuFreeKeywords into qemu_parse_command.c
authorKothapally Madhu Pavan <kmp@linux.vnet.ibm.com>
Mon, 16 Oct 2017 20:20:04 +0000 (01:50 +0530)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 17 Oct 2017 22:52:47 +0000 (18:52 -0400)
Move qemuFreeKeywords into qemu_parse_command.c as
qemuParseKeywordsFree 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
src/qemu/qemu_parse_command.c
src/qemu/qemu_parse_command.h

index 171cdf1b7c2b1e72298ab2adcd82f3ddc840d110..663fce3c3cafcf33f57d87edc0115df8a7376871 100644 (file)
@@ -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);
+    qemuParseKeywordsFree(nkeywords, keywords, values);
     return ret;
 
  error:
-    qemuFreeKeywords(nkeywords, keywords, values);
+    qemuParseKeywordsFree(nkeywords, keywords, values);
     virJSONValueFree(ret);
     return NULL;
 }
index 9f739ae01816a3ad172eadffebf3e50d30b29e98..7bdfbd1640ae5baa2ddb8289a5ee73e5447b98aa 100644 (file)
@@ -381,6 +381,22 @@ static const char *qemuFindEnv(char **progenv,
     return NULL;
 }
 
+
+void
+qemuParseKeywordsFree(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 +417,6 @@ qemuParseKeywords(const char *str,
     char **values = NULL;
     const char *start = str;
     const char *end;
-    size_t i;
 
     *retkeywords = NULL;
     *retvalues = NULL;
@@ -479,12 +494,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);
+    qemuParseKeywordsFree(keywordCount, keywords, values);
     return -1;
 }
 
@@ -949,12 +959,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);
+    qemuParseKeywordsFree(nkeywords, keywords, values);
     return def;
 
  error:
@@ -1132,12 +1137,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);
+    qemuParseKeywordsFree(nkeywords, keywords, values);
     return def;
 
  error:
@@ -1704,13 +1704,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);
-
+    qemuParseKeywordsFree(nkws, kws, vals);
     return ret;
 }
 
@@ -1795,13 +1789,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);
-
+    qemuParseKeywordsFree(nkws, kws, vals);
     return ret;
 
  syntax:
index ed653426bc2d39d7196dbdd382ba5a9bff74dd7a..b3a950a420cf7c5c67482d69d9e20d64537725e2 100644 (file)
@@ -43,6 +43,11 @@ virDomainDefPtr qemuParseCommandLinePid(virCapsPtr caps,
                                         virDomainChrSourceDefPtr *monConfig,
                                         bool *monJSON);
 
+void
+qemuParseKeywordsFree(int nkeywords,
+                     char **keywords,
+                     char **values);
+
 int
 qemuParseKeywords(const char *str,
                   char ***retkeywords,