From nobody Tue Feb 10 04:02:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1576845834; cv=none; d=zohomail.com; s=zohoarc; b=WoUpLjhGdsCVzR57zaRd+VdfxMFEDkHJCE7zpozQDITNSBVduo1Kt0u3vXAoaFiT+MLyO2obuASEsxDr/6vxY6tmzQ+At0qFmpLuAoutKHLIcazVbKV0U83VWqNuJ6TDpPgbl/zg+hFv6Kbz7MOhucAe2gqPULDaf9vUyYfba6E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576845834; h=Content-Type:Content-Transfer-Encoding:Cc: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=0gStxHrK2/dyuniRomJlG1a4yEqUVxoI9RY+mqbiSsI=; b=P1bu0/r/foPHApO6+qABetO0ojaOCl+p/Qi0XNhtSxriJGQpDxvnXByovqmIn5bMzOZyWX0MjWSzlLN4uZyIXpuLQiyvF4W1J0xUzH1PjmjE19Ie1C6zinsWuMc3WHKvbKT79c/zXEB5hbq2QKAEcOuAqskFDq07LSpdjh4nfmU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1576845834423315.07107384742596; Fri, 20 Dec 2019 04:43:54 -0800 (PST) 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-7-g6kNugBrO5mur38vhYydFg-1; Fri, 20 Dec 2019 07:43:50 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 42F33184BECA; Fri, 20 Dec 2019 12:43:45 +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 CD10D5DA75; Fri, 20 Dec 2019 12:43:44 +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 92BD8252E5; Fri, 20 Dec 2019 12:43:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBKChPQt026579 for ; Fri, 20 Dec 2019 07:43:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8C6A31001B07; Fri, 20 Dec 2019 12:43:25 +0000 (UTC) Received: from laerte.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFA731001B00; Fri, 20 Dec 2019 12:43:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576845833; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=0gStxHrK2/dyuniRomJlG1a4yEqUVxoI9RY+mqbiSsI=; b=D2cik7raYi1EjecI+T+n2wgcwZErbD2VoYnzFTUOiP3ZMJKhtFFgrHB96i9h9VWpJ/pXh9 CJ13EVUVCQVcd/Trc9utMQ1GmH1IQXm3aZxJoJpbCfQH+sakBtVGnO1DTAhAzpMd38t0d7 MVNubSh+TV34ehMS85lHoIDqlF6DO4I= From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Fri, 20 Dec 2019 13:43:14 +0100 Message-Id: <20191220124315.1558772-5-fidencio@redhat.com> In-Reply-To: <20191220124315.1558772-1-fidencio@redhat.com> References: <20191220124315.1558772-1-fidencio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCH 4/5] util: Get rid of "no_memory" labels 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.79 on 10.5.11.14 X-MC-Unique: g6kNugBrO5mur38vhYydFg-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) As pointed out by J=C3=A1n Tomko, "no_memory seems suspicious in the times = of abort()". As libvirt decided to take the path to not report OOM and simply abort when it happens, let's get rid of the no_memory labels and simplify the code around them. Mind that virfirewall.c was not touched and still contains no_memory labels. The reason those are left behind, at least for now, is because the conversion seems to be slightly more complicated than the rest, as some other places are relying on firewall->err being set to ENOMEM. Signed-off-by: Fabiano Fid=C3=AAncio --- src/util/virsysinfo.c | 64 ++++++++++++++++--------------------------- src/util/virsysinfo.h | 2 ++ src/util/viruri.c | 28 +++++++------------ 3 files changed, 35 insertions(+), 59 deletions(-) diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 8132ab7a07..e5af4f25e0 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -302,33 +302,27 @@ virSysinfoParsePPCProcessor(const char *base, virSysi= nfoDefPtr ret) virSysinfoDefPtr virSysinfoReadPPC(void) { - virSysinfoDefPtr ret =3D NULL; - char *outbuf =3D NULL; + g_auto(virSysinfoDefPtr) ret =3D NULL; + g_autofree char *outbuf =3D NULL; =20 if (VIR_ALLOC(ret) < 0) - goto no_memory; + return NULL; =20 if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open %s"), CPUINFO); - goto no_memory; + return NULL; } =20 ret->nprocessor =3D 0; ret->processor =3D NULL; if (virSysinfoParsePPCProcessor(outbuf, ret) < 0) - goto no_memory; + return NULL; =20 if (virSysinfoParsePPCSystem(outbuf, &ret->system) < 0) - goto no_memory; - - VIR_FREE(outbuf); - return ret; + return NULL; =20 - no_memory: - VIR_FREE(outbuf); - virSysinfoDefFree(ret); - return NULL; + return g_steal_pointer(&ret); } =20 =20 @@ -433,13 +427,13 @@ virSysinfoParseARMProcessor(const char *base, virSysi= nfoDefPtr ret) virSysinfoDefPtr virSysinfoReadARM(void) { - virSysinfoDefPtr ret =3D NULL; - char *outbuf =3D NULL; + g_auto(virSysinfoDefPtr) ret =3D NULL; + g_autofree char *outbuf =3D NULL; =20 /* Some ARM systems have DMI tables available. */ if ((ret =3D virSysinfoReadDMI())) { if (!virSysinfoDefIsEmpty(ret)) - return ret; + return g_steal_pointer(&ret); virSysinfoDefFree(ret); } =20 @@ -447,29 +441,23 @@ virSysinfoReadARM(void) virResetLastError(); =20 if (VIR_ALLOC(ret) < 0) - goto no_memory; + return NULL; =20 if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open %s"), CPUINFO); - goto no_memory; + return NULL; } =20 ret->nprocessor =3D 0; ret->processor =3D NULL; if (virSysinfoParseARMProcessor(outbuf, ret) < 0) - goto no_memory; + return NULL; =20 if (virSysinfoParseARMSystem(outbuf, &ret->system) < 0) - goto no_memory; - - VIR_FREE(outbuf); - return ret; + return NULL; =20 - no_memory: - VIR_FREE(outbuf); - virSysinfoDefFree(ret); - return NULL; + return g_steal_pointer(&ret); } =20 static char * @@ -606,21 +594,21 @@ virSysinfoParseS390Processor(const char *base, virSys= infoDefPtr ret) virSysinfoDefPtr virSysinfoReadS390(void) { - virSysinfoDefPtr ret =3D NULL; - char *outbuf =3D NULL; + g_auto(virSysinfoDefPtr) ret =3D NULL; + g_autofree char *outbuf =3D NULL; =20 if (VIR_ALLOC(ret) < 0) - goto no_memory; + return NULL; =20 /* Gather info from /proc/cpuinfo */ if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open %s"), CPUINFO); - goto no_memory; + return NULL; } =20 if (virSysinfoParseS390Processor(outbuf, ret) < 0) - goto no_memory; + return NULL; =20 /* Free buffer before reading next file */ VIR_FREE(outbuf); @@ -629,19 +617,13 @@ virSysinfoReadS390(void) if (virFileReadAll(SYSINFO, 8192, &outbuf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open %s"), SYSINFO); - goto no_memory; + return NULL; } =20 if (virSysinfoParseS390System(outbuf, &ret->system) < 0) - goto no_memory; - - VIR_FREE(outbuf); - return ret; + return NULL; =20 - no_memory: - virSysinfoDefFree(ret); - VIR_FREE(outbuf); - return NULL; + return g_steal_pointer(&ret); } =20 =20 diff --git a/src/util/virsysinfo.h b/src/util/virsysinfo.h index f30809294b..3ce936205c 100644 --- a/src/util/virsysinfo.h +++ b/src/util/virsysinfo.h @@ -144,6 +144,8 @@ void virSysinfoChassisDefFree(virSysinfoChassisDefPtr d= ef); void virSysinfoOEMStringsDefFree(virSysinfoOEMStringsDefPtr def); void virSysinfoDefFree(virSysinfoDefPtr def); =20 +G_DEFINE_AUTO_CLEANUP_FREE_FUNC(virSysinfoDefPtr, virSysinfoDefFree, NULL); + int virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 diff --git a/src/util/viruri.c b/src/util/viruri.c index 11163a2b40..1b848bd336 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -71,7 +71,8 @@ virURIParseParams(virURIPtr uri) return 0; =20 while (*query) { - char *name =3D NULL, *value =3D NULL; + g_autofree char *name =3D NULL; + g_autofree char *value =3D NULL; =20 /* Find the next separator, or end of the string. */ end =3D strchr(query, '&'); @@ -92,13 +93,15 @@ virURIParseParams(virURIPtr uri) * and consistent with CGI.pm we assume value is "". */ name =3D xmlURIUnescapeString(query, end - query, NULL); - if (!name) goto no_memory; + if (!name) + return -1; } else if (eq+1 =3D=3D end) { /* Or if we have "name=3D" here (works around annoying * problem when calling xmlURIUnescapeString with len =3D 0). */ name =3D xmlURIUnescapeString(query, eq - query, NULL); - if (!name) goto no_memory; + if (!name) + return -1; } else if (query =3D=3D eq) { /* If the '=3D' character is at the beginning then we have * "=3Dvalue" and consistent with CGI.pm we _ignore_ this. @@ -108,22 +111,15 @@ virURIParseParams(virURIPtr uri) /* Otherwise it's "name=3Dvalue". */ name =3D xmlURIUnescapeString(query, eq - query, NULL); if (!name) - goto no_memory; + return -1; value =3D xmlURIUnescapeString(eq+1, end - (eq+1), NULL); - if (!value) { - VIR_FREE(name); - goto no_memory; - } + if (!value) + return -1; } =20 /* Append to the parameter set. */ - if (virURIParamAppend(uri, name, NULLSTR_EMPTY(value)) < 0) { - VIR_FREE(name); - VIR_FREE(value); + if (virURIParamAppend(uri, name, NULLSTR_EMPTY(value)) < 0) return -1; - } - VIR_FREE(name); - VIR_FREE(value); =20 next: query =3D end; @@ -131,10 +127,6 @@ virURIParseParams(virURIPtr uri) } =20 return 0; - - no_memory: - virReportOOMError(); - return -1; } =20 /** --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list