From nobody Sun May 5 00:07:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1635175968; cv=none; d=zohomail.com; s=zohoarc; b=KenEO4CXgtMbatwkVaVSlsUmeT6lS+Wpfbtif1P8Ay6HA68u1o/64SHL333DBfa6EBiGA6aXYnixKEzw4lhNP5Fw3QLrqByahTmoQNPufb+zlvY1hsEUNUE037JJFBp9kd2OyS0iQbXp1CCjcxKjZlwY5YzXcJ1R6mD4QGka6kk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635175968; 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=XbKGb+Dv1v1o1D148orkymyXzSoq9Uw/QEO4vRF2XYE=; b=k/LfC4bW4AzZ9FCdKD1bsg8qAwOhy//lOkWW548o1J44IV8WY2Hdu7iT+iRGAt/NMcBJXSlTAQmbhThlkAYpG9d2HD2vS4vGmg/pcydCPIZLCdlt4syUrLU2H+0/wAaTUKqfUdpsohTz1Krtzsi+A8A/qNkVnifHHANhAKofnBQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1635175968563935.2948098450768; Mon, 25 Oct 2021 08:32:48 -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-16-lMnJ0xdNNc6ddQOxRPhdQA-1; Mon, 25 Oct 2021 11:32:44 -0400 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 745A7100CC86; Mon, 25 Oct 2021 15:32:39 +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 8020C5DAA5; Mon, 25 Oct 2021 15:32:38 +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 D38674A702; Mon, 25 Oct 2021 15:32:36 +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 19PFWSMe015440 for ; Mon, 25 Oct 2021 11:32:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 366A017CDB; Mon, 25 Oct 2021 15:32:28 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0BA125DAA5 for ; Mon, 25 Oct 2021 15:32:28 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 9D22E24014E; Mon, 25 Oct 2021 17:32:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635175967; 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=XbKGb+Dv1v1o1D148orkymyXzSoq9Uw/QEO4vRF2XYE=; b=eGRdO8eQUsVkc/cu+cgQIEc5edFn1PMcBqpLZlq1aXksBJmSsIUJtqL2Df26EGrSZsXv5t LgxmlTo/g6W1H0S9XhG+IMP47GN+MSss5zvQf1X/sXFHpu4ib2PJmQc2oKMgpqlD0lEgTw kis+SDHfr8y4ktZPxeHkaR4wJ6a4r+Y= X-MC-Unique: lMnJ0xdNNc6ddQOxRPhdQA-1 From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH] node_device: Fix memory leak in udevProcessMediatedDevice Date: Mon, 25 Oct 2021 17:32:25 +0200 Message-Id: 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.79 on 10.5.11.14 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: 1635175970066100001 Content-Type: text/plain; charset="utf-8" One of the paths returned -1 directly without going through the cleanup section. Signed-off-by: Jiri Denemark Reviewed-by: Laine Stump --- src/node_device/node_device_udev.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 7c3bb762b3..cd1722f934 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1020,10 +1020,9 @@ static int udevProcessMediatedDevice(struct udev_device *dev, virNodeDeviceDef *def) { - int ret =3D -1; int iommugrp =3D -1; - char *linkpath =3D NULL; - char *canonicalpath =3D NULL; + g_autofree char *linkpath =3D NULL; + g_autofree char *canonicalpath =3D NULL; virNodeDevCapMdev *data =3D &def->caps->data.mdev; struct udev_device *parent_device =3D NULL; =20 @@ -1039,19 +1038,19 @@ udevProcessMediatedDevice(struct udev_device *dev, virReportSystemError(errno, _("failed to wait for file '%s' to appear"), linkpath); - goto cleanup; + return -1; } =20 if (virFileResolveLink(linkpath, &canonicalpath) < 0) { virReportSystemError(errno, _("failed to resolve '%s'"), linkpath); - goto cleanup; + return -1; } =20 data->type =3D g_path_get_basename(canonicalpath); =20 data->uuid =3D g_strdup(udev_device_get_sysname(dev)); if ((iommugrp =3D virMediatedDeviceGetIOMMUGroupNum(data->uuid)) < 0) - goto cleanup; + return -1; =20 /* lookup the address of parent device */ parent_device =3D udev_device_get_parent(dev); @@ -1072,11 +1071,7 @@ udevProcessMediatedDevice(struct udev_device *dev, =20 data->iommuGroupNumber =3D iommugrp; =20 - ret =3D 0; - cleanup: - VIR_FREE(linkpath); - VIR_FREE(canonicalpath); - return ret; + return 0; } =20 =20 --=20 2.33.1