From nobody Sun Apr 28 22:02:01 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=1685559125; cv=none; d=zohomail.com; s=zohoarc; b=fjWENVKesZtalwarjMUZJOZbFtq3qcveKK4XWF8L5cJTe1WPLkNKbU+bTgTZlCN0+n5DiBGY50uwH/tjCE0jZHNvQFxCbLTxs7hAG35NXCqs6GuOXosrrfA+BasEE+kvz5/VBkYnHC6gedhhAdV+R4pp8Z/1HwqFOau7Izqy2P0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685559125; 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=NRoGJ79ePGGgjl+W9+e0CGy3Dp27L6dPHs/lijUSJZM=; b=oEeW79t3NMlmnRwazQEsL3d0swXyqoNJzqpZb6EXg8bBjUDcxvmdIEMM/slH5L97WrdxeV7rnZ+JEElBhGoqgNjF7XJm/Qtj9DJLpxqW6JKf/f72VmmByqWjsY3us2y9vrxQPh6DupaisEoU054oBS8OgxrsYF50N7upK9uugrw= 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 1685559125387864.7373399183529; Wed, 31 May 2023 11:52:05 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-651-8cEFS__pMZydMWE9fQ524A-1; Wed, 31 May 2023 14:51:32 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C1534811767; Wed, 31 May 2023 18:51:28 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 53D6C112132C; Wed, 31 May 2023 18:51:27 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 07ECD19465B3; Wed, 31 May 2023 18:51:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BE51619465B1 for ; Wed, 31 May 2023 18:51:24 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id AE39640C6CD0; Wed, 31 May 2023 18:51:24 +0000 (UTC) Received: from localhost.localdomain (unknown [10.45.224.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4557E40C6EC4 for ; Wed, 31 May 2023 18:51:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685559124; 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=NRoGJ79ePGGgjl+W9+e0CGy3Dp27L6dPHs/lijUSJZM=; b=JfYJCwL6779O8n/j1vfeokAtNCccoMoqKYaAEEazAGM82m8xqJBhrFv6Gd/EMaqqBQLdf0 VlYUKjCxYOOcepnomx3ttBwO8dwtMLNEAKl9igs+Ugxq3bO7SKZMvNGSI6QP/rfDgy10pE ZdOGwtvz/oTJDHF0aihKuP9T/ujuzys= X-MC-Unique: 8cEFS__pMZydMWE9fQ524A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv3 for 9.4.0] conf: node_device: use separate variables for parsing integers Date: Wed, 31 May 2023 20:50:31 +0200 Message-Id: <378453b18e2f9338537e72cd1e6ec8ee33fda2a0.1685558912.git.jtomko@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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) X-ZM-MESSAGEID: 1685559127054100001 In virNodeDeviceGetSCSIHostCaps, there is a pattern of reusing a tmp value and stealing the pointer. But in two case it is not stolen. Use separate variables for them to avoid mixing autofree with manual free() calls. This fixes the memory leak of the "max_npiv_vports" string. (The other gets freed anyway because it was the last use of "tmp" in the function") Fixes: 8a0cb5f73ade3900546718eabe70cb064c6bd22c Signed-off-by: J=C3=A1n Tomko Reviewed-by: Michal Privoznik --- v3: fix "declaration after statement" warning src/conf/node_device_conf.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index fcee9c027c..172223225f 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2857,29 +2857,32 @@ virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHost = *scsi_host) } =20 if (virVHBAIsVportCapable(NULL, scsi_host->host)) { + g_autofree char *max_vports =3D NULL; + g_autofree char *vports =3D NULL; + scsi_host->flags |=3D VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS; =20 - if (!(tmp =3D virVHBAGetConfig(NULL, scsi_host->host, + if (!(max_vports =3D virVHBAGetConfig(NULL, scsi_host->host, "max_npiv_vports"))) { VIR_WARN("Failed to read max_npiv_vports for host%d", scsi_host->host); goto cleanup; } =20 - if (virStrToLong_i(tmp, NULL, 10, &scsi_host->max_vports) < 0) { - VIR_WARN("Failed to parse value of max_npiv_vports '%s'", tmp); + if (virStrToLong_i(max_vports, NULL, 10, &scsi_host->max_vports) <= 0) { + VIR_WARN("Failed to parse value of max_npiv_vports '%s'", max_= vports); goto cleanup; } =20 - if (!(tmp =3D virVHBAGetConfig(NULL, scsi_host->host, + if (!(vports =3D virVHBAGetConfig(NULL, scsi_host->host, "npiv_vports_inuse"))) { VIR_WARN("Failed to read npiv_vports_inuse for host%d", scsi_host->host); goto cleanup; } =20 - if (virStrToLong_i(tmp, NULL, 10, &scsi_host->vports) < 0) { - VIR_WARN("Failed to parse value of npiv_vports_inuse '%s'", tm= p); + if (virStrToLong_i(vports, NULL, 10, &scsi_host->vports) < 0) { + VIR_WARN("Failed to parse value of npiv_vports_inuse '%s'", vp= orts); goto cleanup; } } --=20 2.40.1