From nobody Wed May 15 14:53:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1644503604; cv=none; d=zohomail.com; s=zohoarc; b=AuIZE+UZ11FhGLCbSruMZZXutnueAM/vQWk2a/nLijtfDc8hf4zRH9BmKg6Lmwn2WBq9CzydUg7+UQuMhswVaQ9YrbuKf2yHwljxcwSwfdrlWUp7J5I94cbA7f+8B0GbP3CP8Num4pD31ekzbiVP02cmOLQERaPzfOUGd+hN9sM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644503604; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=9wQX1zF5vYJ7lMXOCZn4NwyhHFiZJ61bNnwvadRKUl0=; b=lYrJzMmBZYqwd/JYBlR0GunC5OE0eq+qZCV0k6qRWG8PgsEr3f1Flwts6ZoNbuWyPnUnHWKNtZWsUXyy/UXW88xS8xPTVaUtXtWXSP5mX8yM9T2qGlwQ07tuXrM+Kes8yGn2aOry2kNIh7cpM+tzIrKtZH8ThdKwyBGbZYW+miw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1644503604390402.47832051559476; Thu, 10 Feb 2022 06:33:24 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-611-OaWegG-FO-2pe5mtrDe82Q-1; Thu, 10 Feb 2022 09:33:20 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 910302F44; Thu, 10 Feb 2022 14:33:14 +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 4ABEA7D3E5; Thu, 10 Feb 2022 14:33:14 +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 09F124BB7C; Thu, 10 Feb 2022 14:33:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21AEXDHs005002 for ; Thu, 10 Feb 2022 09:33:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3660874EAA; Thu, 10 Feb 2022 14:33:13 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D9FF074EB8 for ; Thu, 10 Feb 2022 14:33:01 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 229572404E6; Thu, 10 Feb 2022 15:33:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644503603; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=9wQX1zF5vYJ7lMXOCZn4NwyhHFiZJ61bNnwvadRKUl0=; b=X+aPt51fkA0YV2evQGDhNTm16YXqmrJeMfPPwZXEoPcWw4mkPPdvtXpuOQozQnAuTGFHMA nmZvEDrkGOcLq17Y075rcOwTuoHbcF6xBdJFWMfwf20qNmjVG0NYroF0s0j2dsBEeTm0bg SCoI2Thh5UCDpC09Uj6SsbcvsN3PrG4= X-MC-Unique: OaWegG-FO-2pe5mtrDe82Q-1 From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH] tests: Fix fd leaks in virpcivpdtest Date: Thu, 10 Feb 2022 15:32:57 +0100 Message-Id: <987ac2f1944adfe81c1760b329219d5e782907c5.1644503577.git.jdenemar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.79 on 10.5.11.16 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644503606603100001 Content-Type: text/plain; charset="utf-8" Tests testVirPCIVPDReadVPDBytes and testVirPCIVPDParseFullVPDInvalid failed to properly close open fildescriptors in some cases. Let's fix it by switching to VIR_AUTOCLOSE in the whole file. Signed-off-by: Jiri Denemark Reviewed-by: Michal Privoznik --- tests/virpcivpdtest.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/tests/virpcivpdtest.c b/tests/virpcivpdtest.c index 3fd40b518c..b4dd68b7aa 100644 --- a/tests/virpcivpdtest.c +++ b/tests/virpcivpdtest.c @@ -432,7 +432,7 @@ testPCIVPDGetFieldValueFormat(const void *data G_GNUC_U= NUSED) static int testVirPCIVPDReadVPDBytes(const void *opaque G_GNUC_UNUSED) { - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; g_autofree uint8_t *buf =3D NULL; uint8_t csum =3D 0; size_t readBytes =3D 0; @@ -471,7 +471,7 @@ testVirPCIVPDReadVPDBytes(const void *opaque G_GNUC_UNU= SED) static int testVirPCIVPDParseVPDStringResource(const void *opaque G_GNUC_UNUSED) { - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; uint8_t csum =3D 0; size_t dataLen =3D 0; bool result =3D false; @@ -488,7 +488,6 @@ testVirPCIVPDParseVPDStringResource(const void *opaque = G_GNUC_UNUSED) return -1; =20 result =3D virPCIVPDParseVPDLargeResourceString(fd, 0, dataLen, &csum,= res); - VIR_FORCE_CLOSE(fd); =20 if (!result) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -541,7 +540,7 @@ testVirPCIVPDValidateExampleReadOnlyFields(virPCIVPDRes= ource *res) static int testVirPCIVPDParseFullVPD(const void *opaque G_GNUC_UNUSED) { - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; size_t dataLen =3D 0; =20 g_autoptr(virPCIVPDResource) res =3D NULL; @@ -560,7 +559,6 @@ testVirPCIVPDParseFullVPD(const void *opaque G_GNUC_UNU= SED) return -1; =20 res =3D virPCIVPDParse(fd); - VIR_FORCE_CLOSE(fd); =20 if (!res) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -609,7 +607,7 @@ testVirPCIVPDParseFullVPD(const void *opaque G_GNUC_UNU= SED) static int testVirPCIVPDParseZeroLengthRW(const void *opaque G_GNUC_UNUSED) { - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; size_t dataLen =3D 0; =20 g_autoptr(virPCIVPDResource) res =3D NULL; @@ -630,7 +628,6 @@ testVirPCIVPDParseZeroLengthRW(const void *opaque G_GNU= C_UNUSED) return -1; =20 res =3D virPCIVPDParse(fd); - VIR_FORCE_CLOSE(fd); =20 if (!res) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -662,7 +659,7 @@ testVirPCIVPDParseZeroLengthRW(const void *opaque G_GNU= C_UNUSED) static int testVirPCIVPDParseNoRW(const void *opaque G_GNUC_UNUSED) { - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; size_t dataLen =3D 0; =20 g_autoptr(virPCIVPDResource) res =3D NULL; @@ -682,7 +679,6 @@ testVirPCIVPDParseNoRW(const void *opaque G_GNUC_UNUSED) return -1; =20 res =3D virPCIVPDParse(fd); - VIR_FORCE_CLOSE(fd); =20 if (!res) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -714,7 +710,7 @@ testVirPCIVPDParseNoRW(const void *opaque G_GNUC_UNUSED) static int testVirPCIVPDParseFullVPDSkipInvalidKeywords(const void *opaque G_GNUC_UNU= SED) { - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; size_t dataLen =3D 0; =20 g_autoptr(virPCIVPDResource) res =3D NULL; @@ -737,7 +733,6 @@ testVirPCIVPDParseFullVPDSkipInvalidKeywords(const void= *opaque G_GNUC_UNUSED) return -1; =20 res =3D virPCIVPDParse(fd); - VIR_FORCE_CLOSE(fd); =20 if (!res) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -759,7 +754,7 @@ testVirPCIVPDParseFullVPDSkipInvalidKeywords(const void= *opaque G_GNUC_UNUSED) static int testVirPCIVPDParseFullVPDSkipInvalidValues(const void *opaque G_GNUC_UNUSE= D) { - int fd =3D -1; + VIR_AUTOCLOSE fd =3D -1; size_t dataLen =3D 0; size_t i =3D 0; virPCIVPDResourceCustom *custom =3D NULL; @@ -792,7 +787,6 @@ testVirPCIVPDParseFullVPDSkipInvalidValues(const void *= opaque G_GNUC_UNUSED) return -1; =20 res =3D virPCIVPDParse(fd); - VIR_FORCE_CLOSE(fd); =20 if (!res) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -868,7 +862,6 @@ testVirPCIVPDParseFullVPDSkipInvalidValues(const void *= opaque G_GNUC_UNUSED) static int testVirPCIVPDParseFullVPDInvalid(const void *opaque G_GNUC_UNUSED) { - int fd =3D -1; size_t dataLen =3D 0; =20 # define VPD_INVALID_ZERO_BYTE \ @@ -963,6 +956,7 @@ testVirPCIVPDParseFullVPDInvalid(const void *opaque G_G= NUC_UNUSED) =20 # define TEST_INVALID_VPD(invalidVPD) \ do { \ + VIR_AUTOCLOSE fd =3D -1; \ g_autoptr(virPCIVPDResource) res =3D NULL; \ const uint8_t testCase[] =3D { invalidVPD }; \ dataLen =3D G_N_ELEMENTS(testCase); \ @@ -973,7 +967,6 @@ testVirPCIVPDParseFullVPDInvalid(const void *opaque G_G= NUC_UNUSED) "Successfully parsed an invalid VPD - this is not expe= cted"); \ return -1; \ } \ - VIR_FORCE_CLOSE(fd); \ } while (0); =20 TEST_INVALID_VPD(VPD_INVALID_ZERO_BYTE); --=20 2.35.1