From nobody Fri Apr 19 04:58:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559652520; cv=none; d=zoho.com; s=zohoarc; b=kJpJ4aoOfA7I8dwbvrfcR9b1+xejdzDuH9DuBS4kPd7PbiQ1VxyT5yQ77jf3TVp3P3spHrt6/dXqS4uxqgus0v+A4FZe4wt5b2DsNJ1Mr+J1/WzEZ4StbCpo3d9hPwTbz8EFDEwsqkWeilrY7rGA08n9I5yX+Qjd7/krGpr4Hhk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559652520; 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:ARC-Authentication-Results; bh=A+zC6O3ql75HR0rVANMxg4MPKEvFf7mHWRLI0KA/Q6k=; b=OlDx+fPYrlRg/N9UufOYlsWVcBPbXiMJXOJdOJP99f2c0YmMgI8/gouuNoXGU8dnBt19iyJQSphOYheHXWRJwuqWRK40o303VCnWsQ2M1+263wpkMpOy5VA6t22gJjqIVWqLOZygZSQgDHWyYI3h6dNueuir1c393mtctTA9ym0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155965252014973.09626020487337; Tue, 4 Jun 2019 05:48:40 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 497B7B8153; Tue, 4 Jun 2019 12:48:33 +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 259FB67277; Tue, 4 Jun 2019 12:48:32 +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 DBFC3206D5; Tue, 4 Jun 2019 12:48:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x54CkqMm026071 for ; Tue, 4 Jun 2019 08:46:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0C4271017E30; Tue, 4 Jun 2019 12:46:52 +0000 (UTC) Received: from kinshicho.brq.redhat.com (unknown [10.43.2.73]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8AB991017E2F for ; Tue, 4 Jun 2019 12:46:51 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Tue, 4 Jun 2019 14:46:46 +0200 Message-Id: <20190604124647.15458-2-abologna@redhat.com> In-Reply-To: <20190604124647.15458-1-abologna@redhat.com> References: <20190604124647.15458-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] qemu: Fix leak in qemuProcessInitCpuAffinity() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 04 Jun 2019 12:48:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In two out of three scenarios we were cleaning up properly after ourselves, but in the remaining one we were leaking cpumapToSet. Refactor the logic so that cpumapToSet is always a freshly allocated bitmap that gets cleaned up automatically thanks to VIR_AUTOPTR(); this also allows us to remove hostcpumap. Reported-by: John Ferlan Signed-off-by: Andrea Bolognani Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_process.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index d44076288e..7d48c95973 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2464,8 +2464,7 @@ static int qemuProcessInitCpuAffinity(virDomainObjPtr vm) { int ret =3D -1; - virBitmapPtr cpumapToSet =3D NULL; - VIR_AUTOPTR(virBitmap) hostcpumap =3D NULL; + VIR_AUTOPTR(virBitmap) cpumapToSet =3D NULL; virDomainNumatuneMemMode mem_mode; qemuDomainObjPrivatePtr priv =3D vm->privateData; =20 @@ -2500,11 +2499,11 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm) if (virNumaNodesetToCPUset(nodeset, &cpumapToSet) < 0) goto cleanup; } else if (vm->def->cputune.emulatorpin) { - cpumapToSet =3D vm->def->cputune.emulatorpin; + if (virBitmapCopy(cpumapToSet, vm->def->cputune.emulatorpin) < 0) + goto cleanup; } else { - if (qemuProcessGetAllCpuAffinity(&hostcpumap) < 0) + if (qemuProcessGetAllCpuAffinity(&cpumapToSet) < 0) goto cleanup; - cpumapToSet =3D hostcpumap; } =20 if (cpumapToSet && --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 04:58:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559652509; cv=none; d=zoho.com; s=zohoarc; b=mWFPpgKzakChZMnwwE6Vd8nkTayPJJ7HisfU+cQ6/O7b+N42l1IhVJ3K77dhvANb4yXkrjVkZQHNkDhs37kuyagWXXYamQ0eOz9ZvOgoIkn/RKSnHGCF17Nml2SGPC3SC5f7kdWPAbAD/BkUVaJeSZsBZDXFnSGqmsdgofxQYGU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559652509; 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:ARC-Authentication-Results; bh=Tev1eu2xktkXxUIAGlQXMRvtKR6Ce3xPByZNsYH3yf0=; b=A16iUPxvCowQ9mQtl9yUI9qMzydBe5UJZrSmN608MMXp8OPJ62Uss/Xsx/QU1/7W+nv73qzElNnZVvX4vHF0p0KuQt24vfyqSHRc6hwo+g/ePftoDycuxc/6fpQcvqdQAJUISamNOkOd1g8DR4/mR8BqcBD/uiEcFQtRqbam1IA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559652509657291.51376051394277; Tue, 4 Jun 2019 05:48:29 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id DE018C18B2D7; Tue, 4 Jun 2019 12:48:13 +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 B393618152; Tue, 4 Jun 2019 12:48:10 +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 67385206D4; Tue, 4 Jun 2019 12:48:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x54CkstL026105 for ; Tue, 4 Jun 2019 08:46:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 78EF41017E30; Tue, 4 Jun 2019 12:46:54 +0000 (UTC) Received: from kinshicho.brq.redhat.com (unknown [10.43.2.73]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0275B1017E37 for ; Tue, 4 Jun 2019 12:46:52 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Tue, 4 Jun 2019 14:46:47 +0200 Message-Id: <20190604124647.15458-3-abologna@redhat.com> In-Reply-To: <20190604124647.15458-1-abologna@redhat.com> References: <20190604124647.15458-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/2] qemu: Drop cleanup label from qemuProcessInitCpuAffinity() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 04 Jun 2019 12:48:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" We're using VIR_AUTOPTR() for everything now, plus the cleanup section was not doing anything useful anyway. Signed-off-by: Andrea Bolognani Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_process.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7d48c95973..42a6271411 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2463,7 +2463,6 @@ qemuProcessGetAllCpuAffinity(virBitmapPtr *cpumapRet) static int qemuProcessInitCpuAffinity(virDomainObjPtr vm) { - int ret =3D -1; VIR_AUTOPTR(virBitmap) cpumapToSet =3D NULL; virDomainNumatuneMemMode mem_mode; qemuDomainObjPrivatePtr priv =3D vm->privateData; @@ -2494,25 +2493,24 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm) priv->autoNodeset, &nodeset, -1) < 0) - goto cleanup; + return -1; =20 if (virNumaNodesetToCPUset(nodeset, &cpumapToSet) < 0) - goto cleanup; + return -1; } else if (vm->def->cputune.emulatorpin) { if (virBitmapCopy(cpumapToSet, vm->def->cputune.emulatorpin) < 0) - goto cleanup; + return -1; } else { if (qemuProcessGetAllCpuAffinity(&cpumapToSet) < 0) - goto cleanup; + return -1; } =20 if (cpumapToSet && - virProcessSetAffinity(vm->pid, cpumapToSet) < 0) - goto cleanup; + virProcessSetAffinity(vm->pid, cpumapToSet) < 0) { + return -1; + } =20 - ret =3D 0; - cleanup: - return ret; + return 0; } #else /* !defined(HAVE_SCHED_GETAFFINITY) && !defined(HAVE_BSD_CPU_AFFINIT= Y) */ static int --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list