mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
tools: use g_new0 instead of VIR_ALLOC*
With the exception of vsh*alloc. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
f67be086a2
commit
157b17f706
@ -1234,8 +1234,7 @@ cmdDomBlkError(vshControl *ctl, const vshCmd *cmd)
|
||||
ndisks = count;
|
||||
|
||||
if (ndisks) {
|
||||
if (VIR_ALLOC_N(disks, ndisks) < 0)
|
||||
goto cleanup;
|
||||
disks = g_new0(virDomainDiskError, ndisks);
|
||||
|
||||
if ((count = virDomainGetDiskErrors(dom, disks, ndisks, 0)) == -1)
|
||||
goto cleanup;
|
||||
@ -1378,10 +1377,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
|
||||
vshPrint(ctl, "%-15s %s\n", _("Security DOI:"), secmodel.doi);
|
||||
|
||||
/* Security labels are only valid for active domains */
|
||||
if (VIR_ALLOC(seclabel) < 0) {
|
||||
virshDomainFree(dom);
|
||||
return false;
|
||||
}
|
||||
seclabel = g_new0(virSecurityLabel, 1);
|
||||
|
||||
if (virDomainGetSecurityLabel(dom, seclabel) == -1) {
|
||||
virshDomainFree(dom);
|
||||
@ -2280,8 +2276,7 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd)
|
||||
flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_NOWAIT;
|
||||
|
||||
if (vshCommandOptBool(cmd, "domain")) {
|
||||
if (VIR_ALLOC_N(domlist, 1) < 0)
|
||||
goto cleanup;
|
||||
domlist = g_new0(virDomainPtr, 1);
|
||||
ndoms = 1;
|
||||
|
||||
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
|
||||
|
@ -1762,8 +1762,7 @@ virshBlockJobWaitInit(vshControl *ctl,
|
||||
virshBlockJobWaitDataPtr ret;
|
||||
virshControlPtr priv = ctl->privData;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
return NULL;
|
||||
ret = g_new0(virshBlockJobWaitData, 1);
|
||||
|
||||
ret->ctl = ctl;
|
||||
ret->dom = dom;
|
||||
@ -8177,8 +8176,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC_N(params, nparams * MIN(show_count, 128)) < 0)
|
||||
goto cleanup;
|
||||
params = g_new0(virTypedParameter, nparams * MIN(show_count, 128));
|
||||
|
||||
while (show_count) {
|
||||
int ncpus = MIN(show_count, 128);
|
||||
@ -8215,8 +8213,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC_N(params, nparams) < 0)
|
||||
goto cleanup;
|
||||
params = g_new0(virTypedParameter, nparams);
|
||||
|
||||
/* passing start_cpu == -1 gives us domain's total status */
|
||||
if ((stats_per_cpu = virDomainGetCPUStats(dom, params, nparams,
|
||||
@ -10086,14 +10083,9 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd)
|
||||
goto cleanup;
|
||||
|
||||
if (setlabel) {
|
||||
if (VIR_ALLOC(secmodel) < 0) {
|
||||
vshError(ctl, "%s", _("Failed to allocate security model"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (VIR_ALLOC(seclabel) < 0) {
|
||||
vshError(ctl, "%s", _("Failed to allocate security label"));
|
||||
goto cleanup;
|
||||
}
|
||||
secmodel = g_new0(virSecurityModel, 1);
|
||||
seclabel = g_new0(virSecurityLabel, 1);
|
||||
|
||||
if (virNodeGetSecurityModel(priv->conn, secmodel) < 0)
|
||||
goto cleanup;
|
||||
if (virDomainGetSecurityLabel(dom, seclabel) < 0)
|
||||
@ -13737,8 +13729,7 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd)
|
||||
}
|
||||
|
||||
if (all) {
|
||||
if (VIR_ALLOC_N(data, VIR_DOMAIN_EVENT_ID_LAST) < 0)
|
||||
goto cleanup;
|
||||
data = g_new0(virshDomEventData, VIR_DOMAIN_EVENT_ID_LAST);
|
||||
for (i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) {
|
||||
data[i].ctl = ctl;
|
||||
data[i].loop = loop;
|
||||
@ -13748,8 +13739,7 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd)
|
||||
data[i].id = -1;
|
||||
}
|
||||
} else {
|
||||
if (VIR_ALLOC_N(data, 1) < 0)
|
||||
goto cleanup;
|
||||
data = g_new0(virshDomEventData, 1);
|
||||
data[0].ctl = ctl;
|
||||
data[0].loop = vshCommandOptBool(cmd, "loop");
|
||||
data[0].count = &count;
|
||||
|
@ -46,8 +46,7 @@ vshAdmServerCompleter(vshControl *ctl,
|
||||
if ((nsrvs = virAdmConnectListServers(priv->conn, &srvs, 0)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (VIR_ALLOC_N(ret, nsrvs + 1) < 0)
|
||||
goto error;
|
||||
ret = g_new0(char *, nsrvs + 1);
|
||||
|
||||
for (i = 0; i < nsrvs; i++) {
|
||||
const char *name = virAdmServerGetName(srvs[i]);
|
||||
@ -59,13 +58,4 @@ vshAdmServerCompleter(vshControl *ctl,
|
||||
VIR_FREE(srvs);
|
||||
|
||||
return ret;
|
||||
|
||||
error:
|
||||
for (; i < nsrvs; i++)
|
||||
virAdmServerFree(srvs[i]);
|
||||
VIR_FREE(srvs);
|
||||
for (i = 0; i < nsrvs; i++)
|
||||
VIR_FREE(ret[i]);
|
||||
VIR_FREE(ret);
|
||||
return ret;
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ static int virLoginShellGetShellArgv(virConfPtr conf,
|
||||
return -1;
|
||||
|
||||
if (rv == 0) {
|
||||
if (VIR_ALLOC_N(*shargv, 2) < 0)
|
||||
*shargv = g_new0(char *, 2);
|
||||
return -1;
|
||||
(*shargv)[0] = g_strdup("/bin/sh");
|
||||
*shargvlen = 1;
|
||||
@ -302,10 +302,8 @@ main(int argc, char **argv)
|
||||
|
||||
if ((nfdlist = virDomainLxcOpenNamespace(dom, &fdlist, 0)) < 0)
|
||||
goto cleanup;
|
||||
if (VIR_ALLOC(secmodel) < 0)
|
||||
goto cleanup;
|
||||
if (VIR_ALLOC(seclabel) < 0)
|
||||
goto cleanup;
|
||||
secmodel = g_new0(virSecurityModel, 1);
|
||||
seclabel = g_new0(virSecurityLabel, 1);
|
||||
if (virNodeGetSecurityModel(conn, secmodel) < 0)
|
||||
goto cleanup;
|
||||
if (virDomainGetSecurityLabel(dom, seclabel) < 0)
|
||||
@ -331,10 +329,7 @@ main(int argc, char **argv)
|
||||
if (tmp) {
|
||||
g_strfreev(shargv);
|
||||
shargvlen = 1;
|
||||
if (VIR_ALLOC_N(shargv[0], shargvlen + 1) < 0) {
|
||||
VIR_FREE(tmp);
|
||||
goto cleanup;
|
||||
}
|
||||
shargv = g_new0(char *, shargvlen + 1);
|
||||
shargv[0] = tmp;
|
||||
shargv[1] = NULL;
|
||||
}
|
||||
|
@ -95,8 +95,7 @@ vshTableRowNew(const char *arg, va_list ap)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(row) < 0)
|
||||
goto error;
|
||||
row = g_new0(vshTableRow, 1);
|
||||
|
||||
while (arg) {
|
||||
char *tmp = NULL;
|
||||
@ -134,8 +133,7 @@ vshTableNew(const char *arg, ...)
|
||||
vshTableRowPtr header = NULL;
|
||||
va_list ap;
|
||||
|
||||
if (VIR_ALLOC(table) < 0)
|
||||
goto error;
|
||||
table = g_new0(vshTable, 1);
|
||||
|
||||
va_start(ap, arg);
|
||||
header = vshTableRowNew(arg, ap);
|
||||
@ -215,8 +213,7 @@ vshTableSafeEncode(const char *s, size_t *width)
|
||||
|
||||
memset(&st, 0, sizeof(st));
|
||||
|
||||
if (VIR_ALLOC_N(buf, (sz * HEX_ENCODE_LENGTH) + 1) < 0)
|
||||
return NULL;
|
||||
buf = g_new0(char, (sz * HEX_ENCODE_LENGTH) + 1);
|
||||
|
||||
ret = buf;
|
||||
*width = 0;
|
||||
@ -369,17 +366,13 @@ vshTablePrint(vshTablePtr table, bool header)
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
char *ret = NULL;
|
||||
|
||||
if (VIR_ALLOC_N(maxwidths, table->rows[0]->ncells))
|
||||
goto cleanup;
|
||||
maxwidths = g_new0(size_t, table->rows[0]->ncells);
|
||||
|
||||
if (VIR_ALLOC_N(widths, table->nrows))
|
||||
goto cleanup;
|
||||
widths = g_new0(size_t *, table->nrows);
|
||||
|
||||
/* retrieve widths of columns */
|
||||
for (i = 0; i < table->nrows; i++) {
|
||||
if (VIR_ALLOC_N(widths[i], table->rows[0]->ncells))
|
||||
goto cleanup;
|
||||
}
|
||||
for (i = 0; i < table->nrows; i++)
|
||||
widths[i] = g_new0(size_t, table->rows[0]->ncells);
|
||||
|
||||
if (vshTableGetColumnsWidths(table, maxwidths, widths, header) < 0)
|
||||
goto cleanup;
|
||||
|
@ -162,10 +162,7 @@ vshStringToArray(const char *str,
|
||||
}
|
||||
|
||||
/* reserve the NULL element at the end */
|
||||
if (VIR_ALLOC_N(arr, nstr_tokens + 1) < 0) {
|
||||
VIR_FREE(str_copied);
|
||||
return -1;
|
||||
}
|
||||
arr = g_new0(char *, nstr_tokens + 1);
|
||||
|
||||
/* tokenize the input string, while treating ,, as a literal comma */
|
||||
nstr_tokens = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user