mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-26 13:22:20 +00:00
Adapt to VIR_ALLOC and virAsprintf in tools/*
This commit is contained in:
parent
3ea84b9548
commit
76fad65bdc
@ -128,7 +128,6 @@ virConsoleEventOnStream(virStreamPtr st,
|
|||||||
if (avail < 1024) {
|
if (avail < 1024) {
|
||||||
if (VIR_REALLOC_N(con->streamToTerminal.data,
|
if (VIR_REALLOC_N(con->streamToTerminal.data,
|
||||||
con->streamToTerminal.length + 1024) < 0) {
|
con->streamToTerminal.length + 1024) < 0) {
|
||||||
virReportOOMError();
|
|
||||||
virConsoleShutdown(con);
|
virConsoleShutdown(con);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -204,7 +203,6 @@ virConsoleEventOnStdin(int watch ATTRIBUTE_UNUSED,
|
|||||||
if (avail < 1024) {
|
if (avail < 1024) {
|
||||||
if (VIR_REALLOC_N(con->terminalToStream.data,
|
if (VIR_REALLOC_N(con->terminalToStream.data,
|
||||||
con->terminalToStream.length + 1024) < 0) {
|
con->terminalToStream.length + 1024) < 0) {
|
||||||
virReportOOMError();
|
|
||||||
virConsoleShutdown(con);
|
virConsoleShutdown(con);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -357,10 +355,8 @@ int vshRunConsole(virDomainPtr dom,
|
|||||||
old_sigpipe = signal(SIGPIPE, do_signal);
|
old_sigpipe = signal(SIGPIPE, do_signal);
|
||||||
got_signal = 0;
|
got_signal = 0;
|
||||||
|
|
||||||
if (VIR_ALLOC(con) < 0) {
|
if (VIR_ALLOC(con) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
con->escapeChar = vshGetEscapeChar(escape_seq);
|
con->escapeChar = vshGetEscapeChar(escape_seq);
|
||||||
con->st = virStreamNew(virDomainGetConnect(dom),
|
con->st = virStreamNew(virDomainGetConnect(dom),
|
||||||
|
@ -709,10 +709,8 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
if (virAsprintf(&xpath, "/domain/devices/interface[(mac/@address = '%s') or "
|
if (virAsprintf(&xpath, "/domain/devices/interface[(mac/@address = '%s') or "
|
||||||
" (target/@dev = '%s')]",
|
" (target/@dev = '%s')]",
|
||||||
macstr, iface) < 0) {
|
macstr, iface) < 0)
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if ((ninterfaces = virXPathNodeSet(xpath, ctxt, &interfaces)) < 0) {
|
if ((ninterfaces = virXPathNodeSet(xpath, ctxt, &interfaces)) < 0) {
|
||||||
vshError(ctl, _("Failed to extract interface information"));
|
vshError(ctl, _("Failed to extract interface information"));
|
||||||
|
@ -6275,7 +6275,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC_N(params, nparams * MIN(show_count, 128)) < 0)
|
if (VIR_ALLOC_N(params, nparams * MIN(show_count, 128)) < 0)
|
||||||
goto no_memory;
|
goto cleanup;
|
||||||
|
|
||||||
while (show_count) {
|
while (show_count) {
|
||||||
int ncpus = MIN(show_count, 128);
|
int ncpus = MIN(show_count, 128);
|
||||||
@ -6324,7 +6324,7 @@ do_show_total:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC_N(params, nparams) < 0)
|
if (VIR_ALLOC_N(params, nparams) < 0)
|
||||||
goto no_memory;
|
goto cleanup;
|
||||||
|
|
||||||
/* passing start_cpu == -1 gives us domain's total status */
|
/* passing start_cpu == -1 gives us domain's total status */
|
||||||
if ((nparams = virDomainGetCPUStats(dom, params, nparams, -1, 1, flags)) < 0)
|
if ((nparams = virDomainGetCPUStats(dom, params, nparams, -1, 1, flags)) < 0)
|
||||||
@ -6354,10 +6354,6 @@ cleanup:
|
|||||||
virDomainFree(dom);
|
virDomainFree(dom);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
no_memory:
|
|
||||||
virReportOOMError();
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
failed_stats:
|
failed_stats:
|
||||||
vshError(ctl, _("Failed to retrieve CPU statistics for domain '%s'"),
|
vshError(ctl, _("Failed to retrieve CPU statistics for domain '%s'"),
|
||||||
virDomainGetName(dom));
|
virDomainGetName(dom));
|
||||||
@ -8843,7 +8839,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
|
|||||||
for (iter = 0; scheme[iter] != NULL; iter++) {
|
for (iter = 0; scheme[iter] != NULL; iter++) {
|
||||||
/* Create our XPATH lookup for the current display's port */
|
/* Create our XPATH lookup for the current display's port */
|
||||||
if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "port") < 0)
|
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 */
|
/* Attempt to get the port number for the current graphics scheme */
|
||||||
tmp = virXPathInt(xpath, ctxt, &port);
|
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 */
|
/* Create our XPATH lookup for the current display's address */
|
||||||
if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "listen") < 0)
|
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
|
/* Attempt to get the listening addr if set for the current
|
||||||
* graphics scheme */
|
* graphics scheme */
|
||||||
@ -8870,7 +8866,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
/* Create our XPATH lookup for the password */
|
/* Create our XPATH lookup for the password */
|
||||||
if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "passwd") < 0)
|
if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "passwd") < 0)
|
||||||
goto no_memory;
|
goto cleanup;
|
||||||
|
|
||||||
/* Attempt to get the password */
|
/* Attempt to get the password */
|
||||||
passwd = virXPathString(xpath, ctxt);
|
passwd = virXPathString(xpath, ctxt);
|
||||||
@ -8885,7 +8881,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
|
|||||||
/* Create our XPATH lookup for TLS Port (automatically skipped
|
/* Create our XPATH lookup for TLS Port (automatically skipped
|
||||||
* for unsupported schemes */
|
* for unsupported schemes */
|
||||||
if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "tlsPort") < 0)
|
if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "tlsPort") < 0)
|
||||||
goto no_memory;
|
goto cleanup;
|
||||||
|
|
||||||
/* Attempt to get the TLS port number */
|
/* Attempt to get the TLS port number */
|
||||||
tmp = virXPathInt(xpath, ctxt, &tls_port);
|
tmp = virXPathInt(xpath, ctxt, &tls_port);
|
||||||
@ -8951,10 +8947,6 @@ cleanup:
|
|||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
virDomainFree(dom);
|
virDomainFree(dom);
|
||||||
return ret;
|
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)
|
if (n1_child_size == 0 && n2_child_size == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!(bitmap = virBitmapNew(n1_child_size))) {
|
if (!(bitmap = virBitmapNew(n1_child_size)))
|
||||||
virReportOOMError();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
child2 = n2->children;
|
child2 = n2->children;
|
||||||
while (child2) {
|
while (child2) {
|
||||||
@ -9841,10 +9831,8 @@ cleanup:
|
|||||||
VIR_FREE(disk_type);
|
VIR_FREE(disk_type);
|
||||||
if (xml_buf) {
|
if (xml_buf) {
|
||||||
int len = xmlBufferLength(xml_buf);
|
int len = xmlBufferLength(xml_buf);
|
||||||
if (VIR_ALLOC_N(ret, len + 1) < 0) {
|
if (VIR_ALLOC_N(ret, len + 1) < 0)
|
||||||
virReportOOMError();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
memcpy(ret, (char *)xmlBufferContent(xml_buf), len);
|
memcpy(ret, (char *)xmlBufferContent(xml_buf), len);
|
||||||
ret[len] = '\0';
|
ret[len] = '\0';
|
||||||
xmlBufferFree(xml_buf);
|
xmlBufferFree(xml_buf);
|
||||||
|
@ -197,7 +197,6 @@ vshStringToArray(const char *str,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC_N(arr, nstr_tokens) < 0) {
|
if (VIR_ALLOC_N(arr, nstr_tokens) < 0) {
|
||||||
virReportOOMError();
|
|
||||||
VIR_FREE(str_copied);
|
VIR_FREE(str_copied);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user