From nobody Mon Feb 9 17:24:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1612600506; cv=none; d=zohomail.com; s=zohoarc; b=lHIZurgDD+3P495rker1QyMkaTLYCT9WGNRq1eynNUT6Lz2tQhdxzBCwU6Aqu/E3yhA8TpoVQN+mKimAn0iDt7rCJwSPVu1C7rhmiQC/d8iKoEVJMLak50DTSRdkaGFYGWeN+aQQKuHdsZZjuMW82nU3idcEnpeBDrx6H3muIJM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600506; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=POeiAURAgBCyqtu7zEWjyR4+gYI6aRoU+/3GdlJoqAw=; b=ZGixVBlhC04BTS24jdek3txq6Ucn0kdVGKpgjJqhmZSlM+tY6JzXirSe2FdzOObHIcodXGmWU1baaOQA3DDiiLZ/XOCEsV2R6HMyeSfXgDoO4gL9QdO6WwRhfuO///1SmdMy7d6lOMUPRHslpwlRsqMEiICuSWl+uRHUijN+qOg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1612600506931620.4774224297898; Sat, 6 Feb 2021 00:35:06 -0800 (PST) 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-388-MgLKkoxDMnq0blLKYL4txQ-1; Sat, 06 Feb 2021 03:34:23 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 21287107ACF2; Sat, 6 Feb 2021 08:34:17 +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 EC82D101E242; Sat, 6 Feb 2021 08:34:16 +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 B830B5807E; Sat, 6 Feb 2021 08:34:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1168YFvI005287 for ; Sat, 6 Feb 2021 03:34:15 -0500 Received: by smtp.corp.redhat.com (Postfix) id 218DB60C77; Sat, 6 Feb 2021 08:34:15 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 703B260C76 for ; Sat, 6 Feb 2021 08:34:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600505; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=POeiAURAgBCyqtu7zEWjyR4+gYI6aRoU+/3GdlJoqAw=; b=b8cDPnstRbuLlz1Xg5ooJxjtDRZoeQCQ5bY093fuMAbpjN8/znmr2p4YgugFNCs8rx9H7C chgHD4FDc1THt06ruB41hB7CioKwsdzUKv4RZPFquCZM6O55CtbYK6mTPrpFzqqG+hBzt/ 2KT1+vCBV7uTjy9UzzP1WetJDYwOmI0= X-MC-Unique: MgLKkoxDMnq0blLKYL4txQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 25/40] qemuProcessUpdateDevices: Refactor cleanup and memory handling Date: Sat, 6 Feb 2021 09:32:47 +0100 Message-Id: <733f4200f6c5789ef4c88e5681a3d860fd01e816.1612599659.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.84 on 10.5.11.22 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) Content-Type: text/plain; charset="utf-8" Use automatic memory freeing and remove the 'cleanup' label. Also make it a bit more obvious that nothing happens if the 'old' list wasn't present. Signed-off-by: Peter Krempa --- src/qemu/qemu_process.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 30cfa4d485..1fd3230e97 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3798,32 +3798,23 @@ qemuProcessUpdateDevices(virQEMUDriverPtr driver, { qemuDomainObjPrivatePtr priv =3D vm->privateData; virDomainDeviceDef dev; - const char **qemuDevices; - char **old; - char **tmp; - int ret =3D -1; + g_auto(GStrv) old =3D g_steal_pointer(&priv->qemuDevices); + GStrv tmp; - old =3D priv->qemuDevices; - priv->qemuDevices =3D NULL; if (qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) - goto cleanup; + return -1; - qemuDevices =3D (const char **)priv->qemuDevices; - if ((tmp =3D old)) { - while (*tmp) { - if (!virStringListHasString(qemuDevices, *tmp) && - virDomainDefFindDevice(vm->def, *tmp, &dev, false) =3D=3D = 0 && - qemuDomainRemoveDevice(driver, vm, &dev) < 0) { - goto cleanup; - } - tmp++; - } + if (!old) + return 0; + + for (tmp =3D old; *tmp; tmp++) { + if (!virStringListHasString((const char **) priv->qemuDevices, *tm= p) && + virDomainDefFindDevice(vm->def, *tmp, &dev, false) =3D=3D 0 && + qemuDomainRemoveDevice(driver, vm, &dev)) + return -1; } - ret =3D 0; - cleanup: - g_strfreev(old); - return ret; + return 0; } static int --=20 2.29.2