From nobody Tue Oct 28 21:10:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152311236551639.60414068894738; Sat, 7 Apr 2018 07:46:05 -0700 (PDT) Received: from localhost ([::1]:32909 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f4p6S-0003wL-HV for importer@patchew.org; Sat, 07 Apr 2018 10:46:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f4p4U-0002mw-QS for qemu-devel@nongnu.org; Sat, 07 Apr 2018 10:44:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f4p4Q-0001ET-PR for qemu-devel@nongnu.org; Sat, 07 Apr 2018 10:44:02 -0400 Received: from 1.mo179.mail-out.ovh.net ([178.33.111.220]:46618) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f4p4Q-0001Du-IF for qemu-devel@nongnu.org; Sat, 07 Apr 2018 10:43:58 -0400 Received: from player737.ha.ovh.net (unknown [10.109.120.125]) by mo179.mail-out.ovh.net (Postfix) with ESMTP id 1F848B2389 for ; Sat, 7 Apr 2018 16:43:57 +0200 (CEST) Received: from [192.168.0.243] (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player737.ha.ovh.net (Postfix) with ESMTPA id A4045E00AF; Sat, 7 Apr 2018 16:43:52 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Sat, 07 Apr 2018 16:43:46 +0200 Message-ID: <152311222681.203086.8874800175539040298.stgit@bahia> In-Reply-To: <152311221072.203086.16767398863033055271.stgit@bahia> References: <152311221072.203086.16767398863033055271.stgit@bahia> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 15648882807289846071 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtgedrhedtgdektdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.33.111.220 Subject: [Qemu-devel] [PATCH v2 1/2] vfio-ccw: fix memory leaks in vfio_ccw_realize() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alex Williamson , Cornelia Huck , qemu-s390x@nongnu.org, qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 If the subchannel is already attached or if vfio_get_device() fails, the code jumps to the 'out_device_err' label and doesn't free the string it has just allocated. The code should be reworked so that vcdev->vdev.name only gets set when the device has been attached, and freed when it is about to be detached. This could be achieved with the addition of a vfio_ccw_get_device() function that would be the counterpart of vfio_put_device(). But this is a more elaborate cleanup that should be done in a follow-up. For now, let's just add calls to g_free() on the buggy error paths. Signed-off-by: Greg Kurz --- hw/vfio/ccw.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 4e5855741a64..fe34b507699f 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -357,11 +357,13 @@ static void vfio_ccw_realize(DeviceState *dev, Error = **errp) if (strcmp(vbasedev->name, vcdev->vdev.name) =3D=3D 0) { error_setg(&err, "vfio: subchannel %s has already been attache= d", vcdev->vdev.name); + g_free(vcdev->vdev.name); goto out_device_err; } } =20 if (vfio_get_device(group, cdev->mdevid, &vcdev->vdev, &err)) { + g_free(vcdev->vdev.name); goto out_device_err; } =20