From nobody Sun Feb 8 19:40:07 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 1488889155285947.0906358038524; Tue, 7 Mar 2017 04:19:15 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v27CFk9Z054989; Tue, 7 Mar 2017 07:15:47 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v27CFk9q003945 for ; Tue, 7 Mar 2017 07:15:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 14E7B2D655; Tue, 7 Mar 2017 12:15:46 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-9.phx2.redhat.com [10.3.117.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id C65DD2D654 for ; Tue, 7 Mar 2017 12:15:45 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 7 Mar 2017 07:15:41 -0500 Message-Id: <20170307121542.25287-2-jferlan@redhat.com> In-Reply-To: <20170307121542.25287-1-jferlan@redhat.com> References: <20170307121542.25287-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] util: Resource some resource leaks in virsysinfo code 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Calls to virFileReadAll after a VIR_ALLOC that return NULL all show a memory leak since 'ret' isn't virSysinfoDefFree'd and normal path "return ret" doesn't free outbuf. Reported by Coverity Signed-off-by: John Ferlan --- src/util/virsysinfo.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 7b54bda..14c17a8 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -270,7 +270,7 @@ virSysinfoReadPPC(void) if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open %s"), CPUINFO); - return NULL; + goto no_memory; } =20 ret->nprocessor =3D 0; @@ -281,10 +281,12 @@ virSysinfoReadPPC(void) if (virSysinfoParsePPCSystem(outbuf, &ret->system) < 0) goto no_memory; =20 + VIR_FREE(outbuf); return ret; =20 no_memory: VIR_FREE(outbuf); + virSysinfoDefFree(ret); return NULL; } =20 @@ -402,7 +404,7 @@ virSysinfoReadARM(void) if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open %s"), CPUINFO); - return NULL; + goto no_memory; } =20 ret->nprocessor =3D 0; @@ -413,10 +415,12 @@ virSysinfoReadARM(void) if (virSysinfoParseARMSystem(outbuf, &ret->system) < 0) goto no_memory; =20 + VIR_FREE(outbuf); return ret; =20 no_memory: VIR_FREE(outbuf); + virSysinfoDefFree(ret); return NULL; } =20 @@ -539,7 +543,7 @@ virSysinfoReadS390(void) if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open %s"), CPUINFO); - return NULL; + goto no_memory; } =20 ret->nprocessor =3D 0; @@ -554,12 +558,13 @@ virSysinfoReadS390(void) if (virFileReadAll(SYSINFO, 8192, &outbuf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open %s"), SYSINFO); - return NULL; + goto no_memory; } =20 if (virSysinfoParseS390System(outbuf, &ret->system) < 0) goto no_memory; =20 + VIR_FREE(outbuf); return ret; =20 no_memory: --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list