[libvirt] [PATCH v1 37/37] Adapt to VIR_ALLOC and virAsprintf in tools/*

Michal Privoznik mprivozn at redhat.com
Thu Jul 4 12:07:00 UTC 2013


---
 tools/console.c              |  6 +-----
 tools/virsh-domain-monitor.c |  4 +---
 tools/virsh-domain.c         | 28 ++++++++--------------------
 tools/virsh.c                |  1 -
 4 files changed, 10 insertions(+), 29 deletions(-)

diff --git a/tools/console.c b/tools/console.c
index 9abfb58..6c24fcf 100644
--- a/tools/console.c
+++ b/tools/console.c
@@ -128,7 +128,6 @@ virConsoleEventOnStream(virStreamPtr st,
         if (avail < 1024) {
             if (VIR_REALLOC_N(con->streamToTerminal.data,
                               con->streamToTerminal.length + 1024) < 0) {
-                virReportOOMError();
                 virConsoleShutdown(con);
                 return;
             }
@@ -204,7 +203,6 @@ virConsoleEventOnStdin(int watch ATTRIBUTE_UNUSED,
         if (avail < 1024) {
             if (VIR_REALLOC_N(con->terminalToStream.data,
                               con->terminalToStream.length + 1024) < 0) {
-                virReportOOMError();
                 virConsoleShutdown(con);
                 return;
             }
@@ -357,10 +355,8 @@ int vshRunConsole(virDomainPtr dom,
     old_sigpipe = signal(SIGPIPE, do_signal);
     got_signal = 0;
 
-    if (VIR_ALLOC(con) < 0) {
-        virReportOOMError();
+    if (VIR_ALLOC(con) < 0)
         goto cleanup;
-    }
 
     con->escapeChar = vshGetEscapeChar(escape_seq);
     con->st = virStreamNew(virDomainGetConnect(dom),
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 58d6d40..f7f7fb6 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -709,10 +709,8 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd)
 
     if (virAsprintf(&xpath, "/domain/devices/interface[(mac/@address = '%s') or "
                             "                          (target/@dev = '%s')]",
-                           macstr, iface) < 0) {
-        virReportOOMError();
+                           macstr, iface) < 0)
         goto cleanup;
-    }
 
     if ((ninterfaces = virXPathNodeSet(xpath, ctxt, &interfaces)) < 0) {
         vshError(ctl, _("Failed to extract interface information"));
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 5257416..1eb8ff8 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -6275,7 +6275,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
     }
 
     if (VIR_ALLOC_N(params, nparams * MIN(show_count, 128)) < 0)
-        goto no_memory;
+        goto cleanup;
 
     while (show_count) {
         int ncpus = MIN(show_count, 128);
@@ -6324,7 +6324,7 @@ do_show_total:
     }
 
     if (VIR_ALLOC_N(params, nparams) < 0)
-        goto no_memory;
+        goto cleanup;
 
     /* passing start_cpu == -1 gives us domain's total status */
     if ((nparams = virDomainGetCPUStats(dom, params, nparams, -1, 1, flags)) < 0)
@@ -6354,10 +6354,6 @@ cleanup:
     virDomainFree(dom);
     return ret;
 
-no_memory:
-    virReportOOMError();
-    goto cleanup;
-
 failed_stats:
     vshError(ctl, _("Failed to retrieve CPU statistics for domain '%s'"),
              virDomainGetName(dom));
@@ -8843,7 +8839,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
     for (iter = 0; scheme[iter] != NULL; iter++) {
         /* Create our XPATH lookup for the current display's port */
         if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "port") < 0)
-            goto no_memory;
+            goto cleanup;
 
         /* Attempt to get the port number for the current graphics scheme */
         tmp = virXPathInt(xpath, ctxt, &port);
@@ -8856,7 +8852,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
 
         /* Create our XPATH lookup for the current display's address */
         if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "listen") < 0)
-            goto no_memory;
+            goto cleanup;
 
         /* Attempt to get the listening addr if set for the current
          * graphics scheme */
@@ -8870,7 +8866,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
 
         /* Create our XPATH lookup for the password */
         if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "passwd") < 0)
-            goto no_memory;
+            goto cleanup;
 
         /* Attempt to get the password */
         passwd = virXPathString(xpath, ctxt);
@@ -8885,7 +8881,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
         /* Create our XPATH lookup for TLS Port (automatically skipped
          * for unsupported schemes */
         if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "tlsPort") < 0)
-            goto no_memory;
+            goto cleanup;
 
         /* Attempt to get the TLS port number */
         tmp = virXPathInt(xpath, ctxt, &tls_port);
@@ -8951,10 +8947,6 @@ cleanup:
     xmlFreeDoc(xml);
     virDomainFree(dom);
     return ret;
-
-no_memory:
-    virReportOOMError();
-    goto cleanup;
 }
 
 /*
@@ -9192,10 +9184,8 @@ vshNodeIsSuperset(xmlNodePtr n1, xmlNodePtr n2)
     if (n1_child_size == 0 && n2_child_size == 0)
         return true;
 
-    if (!(bitmap = virBitmapNew(n1_child_size))) {
-        virReportOOMError();
+    if (!(bitmap = virBitmapNew(n1_child_size)))
         return false;
-    }
 
     child2 = n2->children;
     while (child2) {
@@ -9841,10 +9831,8 @@ cleanup:
     VIR_FREE(disk_type);
     if (xml_buf) {
         int len = xmlBufferLength(xml_buf);
-        if (VIR_ALLOC_N(ret, len + 1) < 0) {
-            virReportOOMError();
+        if (VIR_ALLOC_N(ret, len + 1) < 0)
             return NULL;
-        }
         memcpy(ret, (char *)xmlBufferContent(xml_buf), len);
         ret[len] = '\0';
         xmlBufferFree(xml_buf);
diff --git a/tools/virsh.c b/tools/virsh.c
index af2bb76..a7e7f0c 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -197,7 +197,6 @@ vshStringToArray(const char *str,
     }
 
     if (VIR_ALLOC_N(arr, nstr_tokens) < 0) {
-        virReportOOMError();
         VIR_FREE(str_copied);
         return -1;
     }
-- 
1.8.1.5




More information about the libvir-list mailing list