From nobody Mon Feb 9 15:10:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600892081; cv=none; d=zohomail.com; s=zohoarc; b=kRd4fMcwJMUSCCJZVaQ7mg0t2qiQEiWSW3rV3VqR/V1pQ0RYHqWlnwxMlFaIKjaBIjBBjG2dXKL3V8fSQQakVv3gOx0CHRs0yojTI+i7LAoxH6n9rCXJQ0ZN01Gb3iBmAxmsZSqkcPvFzAKSXn7wejhztAfXd1grKJZUBiSlpKA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600892081; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XafskzOTuE98lCdZ45PcR9uug5dLT1CJ4MUoo457DmM=; b=Vmsozj79bshuC+nNKQkXP/4H7lYtAXYGXOE1s6GLK6xYfkeojCOdXhXmzV7Dz5UZy+iTHSOG5b3oUtlszU3acDZYKmJ0RrykIbZJRNcJxroUa/r8Z+xGDQoLaRMFBn0pUt67n63qpA+jzhQBc/rmqAwEfSYbr1v8jJ21uFaywHo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1600892081665470.69857646357957; Wed, 23 Sep 2020 13:14:41 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-413-1Ak41HqtMeysGWwUhCXofg-1; Wed, 23 Sep 2020 16:14:37 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 58580805EE8; Wed, 23 Sep 2020 20:14:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 36F051002C03; Wed, 23 Sep 2020 20:14:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 03CF18C7C9; Wed, 23 Sep 2020 20:14:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08NKBLXM028471 for ; Wed, 23 Sep 2020 16:11:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id B35F05D990; Wed, 23 Sep 2020 20:11:21 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A61D5D98D for ; Wed, 23 Sep 2020 20:11:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600892080; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=XafskzOTuE98lCdZ45PcR9uug5dLT1CJ4MUoo457DmM=; b=KFIJq04DY7mv16AEXfT23R7Dm+AgfgYrM062rjttpRnGvYYQtgtind0K/TNJo5NB6++QFy M4jRm3GJskpdd1oOFRSAe5vh8UaLriA+8taru8FV8vm1Q3IlMV5DpQwLVwyO6+8hd6Bo62 Dxcm85ebxKlugWMwFZVhpWChLwKjGJI= X-MC-Unique: 1Ak41HqtMeysGWwUhCXofg-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 5/5] tools: use g_new0 instead of VIR_ALLOC* Date: Wed, 23 Sep 2020 22:11:08 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) With the exception of vsh*alloc. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Daniel Henrique Barboza --- tools/virsh-domain-monitor.c | 11 +++-------- tools/virsh-domain.c | 26 ++++++++------------------ tools/virt-admin-completer.c | 12 +----------- tools/virt-login-shell-helper.c | 13 ++++--------- tools/vsh-table.c | 21 +++++++-------------- tools/vsh.c | 5 +---- 6 files changed, 24 insertions(+), 64 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 848efc8aa3..c8a7c0f1b7 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1234,8 +1234,7 @@ cmdDomBlkError(vshControl *ctl, const vshCmd *cmd) ndisks =3D count; =20 if (ndisks) { - if (VIR_ALLOC_N(disks, ndisks) < 0) - goto cleanup; + disks =3D g_new0(virDomainDiskError, ndisks); =20 if ((count =3D virDomainGetDiskErrors(dom, disks, ndisks, 0)) =3D= =3D -1) goto cleanup; @@ -1378,10 +1377,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%-15s %s\n", _("Security DOI:"), secmodel.doi); =20 /* Security labels are only valid for active domains */ - if (VIR_ALLOC(seclabel) < 0) { - virshDomainFree(dom); - return false; - } + seclabel =3D g_new0(virSecurityLabel, 1); =20 if (virDomainGetSecurityLabel(dom, seclabel) =3D=3D -1) { virshDomainFree(dom); @@ -2280,8 +2276,7 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd) flags |=3D VIR_CONNECT_GET_ALL_DOMAINS_STATS_NOWAIT; =20 if (vshCommandOptBool(cmd, "domain")) { - if (VIR_ALLOC_N(domlist, 1) < 0) - goto cleanup; + domlist =3D g_new0(virDomainPtr, 1); ndoms =3D 1; =20 while ((opt =3D vshCommandOptArgv(ctl, cmd, opt))) { diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 32edfc0398..dfcba04682 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -1762,8 +1762,7 @@ virshBlockJobWaitInit(vshControl *ctl, virshBlockJobWaitDataPtr ret; virshControlPtr priv =3D ctl->privData; =20 - if (VIR_ALLOC(ret) < 0) - return NULL; + ret =3D g_new0(virshBlockJobWaitData, 1); =20 ret->ctl =3D ctl; ret->dom =3D dom; @@ -8177,8 +8176,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd) goto cleanup; } =20 - if (VIR_ALLOC_N(params, nparams * MIN(show_count, 128)) < 0) - goto cleanup; + params =3D g_new0(virTypedParameter, nparams * MIN(show_count, 128)); =20 while (show_count) { int ncpus =3D MIN(show_count, 128); @@ -8215,8 +8213,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd) goto cleanup; } =20 - if (VIR_ALLOC_N(params, nparams) < 0) - goto cleanup; + params =3D g_new0(virTypedParameter, nparams); =20 /* passing start_cpu =3D=3D -1 gives us domain's total status */ if ((stats_per_cpu =3D virDomainGetCPUStats(dom, params, nparams, @@ -10086,14 +10083,9 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd= *cmd) goto cleanup; =20 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 =3D g_new0(virSecurityModel, 1); + seclabel =3D 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) } =20 if (all) { - if (VIR_ALLOC_N(data, VIR_DOMAIN_EVENT_ID_LAST) < 0) - goto cleanup; + data =3D g_new0(virshDomEventData, VIR_DOMAIN_EVENT_ID_LAST); for (i =3D 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) { data[i].ctl =3D ctl; data[i].loop =3D loop; @@ -13748,8 +13739,7 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) data[i].id =3D -1; } } else { - if (VIR_ALLOC_N(data, 1) < 0) - goto cleanup; + data =3D g_new0(virshDomEventData, 1); data[0].ctl =3D ctl; data[0].loop =3D vshCommandOptBool(cmd, "loop"); data[0].count =3D &count; diff --git a/tools/virt-admin-completer.c b/tools/virt-admin-completer.c index 7201bb71eb..61004beeb5 100644 --- a/tools/virt-admin-completer.c +++ b/tools/virt-admin-completer.c @@ -46,8 +46,7 @@ vshAdmServerCompleter(vshControl *ctl, if ((nsrvs =3D virAdmConnectListServers(priv->conn, &srvs, 0)) < 0) return NULL; =20 - if (VIR_ALLOC_N(ret, nsrvs + 1) < 0) - goto error; + ret =3D g_new0(char *, nsrvs + 1); =20 for (i =3D 0; i < nsrvs; i++) { const char *name =3D virAdmServerGetName(srvs[i]); @@ -59,13 +58,4 @@ vshAdmServerCompleter(vshControl *ctl, VIR_FREE(srvs); =20 return ret; - - error: - for (; i < nsrvs; i++) - virAdmServerFree(srvs[i]); - VIR_FREE(srvs); - for (i =3D 0; i < nsrvs; i++) - VIR_FREE(ret[i]); - VIR_FREE(ret); - return ret; } diff --git a/tools/virt-login-shell-helper.c b/tools/virt-login-shell-helpe= r.c index cc6836382a..0e7987bf82 100644 --- a/tools/virt-login-shell-helper.c +++ b/tools/virt-login-shell-helper.c @@ -99,7 +99,7 @@ static int virLoginShellGetShellArgv(virConfPtr conf, return -1; =20 if (rv =3D=3D 0) { - if (VIR_ALLOC_N(*shargv, 2) < 0) + *shargv =3D g_new0(char *, 2); return -1; (*shargv)[0] =3D g_strdup("/bin/sh"); *shargvlen =3D 1; @@ -302,10 +302,8 @@ main(int argc, char **argv) =20 if ((nfdlist =3D virDomainLxcOpenNamespace(dom, &fdlist, 0)) < 0) goto cleanup; - if (VIR_ALLOC(secmodel) < 0) - goto cleanup; - if (VIR_ALLOC(seclabel) < 0) - goto cleanup; + secmodel =3D g_new0(virSecurityModel, 1); + seclabel =3D 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 =3D 1; - if (VIR_ALLOC_N(shargv[0], shargvlen + 1) < 0) { - VIR_FREE(tmp); - goto cleanup; - } + shargv =3D g_new0(char *, shargvlen + 1); shargv[0] =3D tmp; shargv[1] =3D NULL; } diff --git a/tools/vsh-table.c b/tools/vsh-table.c index a727ac17b5..4471368687 100644 --- a/tools/vsh-table.c +++ b/tools/vsh-table.c @@ -95,8 +95,7 @@ vshTableRowNew(const char *arg, va_list ap) goto error; } =20 - if (VIR_ALLOC(row) < 0) - goto error; + row =3D g_new0(vshTableRow, 1); =20 while (arg) { char *tmp =3D NULL; @@ -134,8 +133,7 @@ vshTableNew(const char *arg, ...) vshTableRowPtr header =3D NULL; va_list ap; =20 - if (VIR_ALLOC(table) < 0) - goto error; + table =3D g_new0(vshTable, 1); =20 va_start(ap, arg); header =3D vshTableRowNew(arg, ap); @@ -215,8 +213,7 @@ vshTableSafeEncode(const char *s, size_t *width) =20 memset(&st, 0, sizeof(st)); =20 - if (VIR_ALLOC_N(buf, (sz * HEX_ENCODE_LENGTH) + 1) < 0) - return NULL; + buf =3D g_new0(char, (sz * HEX_ENCODE_LENGTH) + 1); =20 ret =3D buf; *width =3D 0; @@ -369,17 +366,13 @@ vshTablePrint(vshTablePtr table, bool header) g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; char *ret =3D NULL; =20 - if (VIR_ALLOC_N(maxwidths, table->rows[0]->ncells)) - goto cleanup; + maxwidths =3D g_new0(size_t, table->rows[0]->ncells); =20 - if (VIR_ALLOC_N(widths, table->nrows)) - goto cleanup; + widths =3D g_new0(size_t *, table->nrows); =20 /* retrieve widths of columns */ - for (i =3D 0; i < table->nrows; i++) { - if (VIR_ALLOC_N(widths[i], table->rows[0]->ncells)) - goto cleanup; - } + for (i =3D 0; i < table->nrows; i++) + widths[i] =3D g_new0(size_t, table->rows[0]->ncells); =20 if (vshTableGetColumnsWidths(table, maxwidths, widths, header) < 0) goto cleanup; diff --git a/tools/vsh.c b/tools/vsh.c index 87c409e4aa..0eddd5349d 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -162,10 +162,7 @@ vshStringToArray(const char *str, } =20 /* reserve the NULL element at the end */ - if (VIR_ALLOC_N(arr, nstr_tokens + 1) < 0) { - VIR_FREE(str_copied); - return -1; - } + arr =3D g_new0(char *, nstr_tokens + 1); =20 /* tokenize the input string, while treating ,, as a literal comma */ nstr_tokens =3D 0; --=20 2.26.2