From nobody Sun Feb 8 12:37:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1611940305; cv=none; d=zohomail.com; s=zohoarc; b=Dyz5Semcjj8GWPvvRlCGJ1pTVe49FZicMNE5IEFoWW7UUvPJrjxXnVDe23qhtt92GmMgmV8CGZ9YtS7LH4PalrgUirZ/e2UrC56mFhiMa1P5Ao/Hvcypu0AmPn0nSQfS3Ilejm0l4P0TQOziLT3pEhkUpcc/o1UQb63mLi6c1bU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611940305; h=Content-Type:Content-Transfer-Encoding:Cc: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=5W85jRKRkTM28M78Uqk941jBiKL2UVivuVHcLvFjqho=; b=WGKDWSr6VD5DOTwNTtMBL0RmVYKHRuNxf0RoLNLb3kovCF7sut8vxwC+vzncoUFi9AZmGdQhYWQMBIQzDd4ohTwAfG8Cb+seEpkxDW9RX3rrddkqnB0KYfm9H/rc71D19GzFvFKhHQIEKjmZIEYft7p75vXltkxMJQspSQGk20E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611940305515526.6978736682977; Fri, 29 Jan 2021 09:11:45 -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-320-0M19v0LSPm29LaTiq2M6qA-1; Fri, 29 Jan 2021 12:11:41 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2DC36107ACFB; Fri, 29 Jan 2021 17:11:35 +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 0B8B960CE6; Fri, 29 Jan 2021 17:11:35 +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 C888E5003E; Fri, 29 Jan 2021 17:11:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10THBXjU018738 for ; Fri, 29 Jan 2021 12:11:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 319F61945C; Fri, 29 Jan 2021 17:11:33 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-115-94.ams2.redhat.com [10.36.115.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DD5A5D705; Fri, 29 Jan 2021 17:11:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611940304; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=5W85jRKRkTM28M78Uqk941jBiKL2UVivuVHcLvFjqho=; b=FhwVfzyPJN4L/gfrXHoEplQEf6K2jYSIKUD0Nb37ENVBx2wk6AvHD/cJzm9ongaAxvnvHX 0JTKvW08hWUal7FO4NTxh4lXnGPDxMNMxZWp+kjEKpTXi9RYatAxzIzsfdQn1doyRcoXMr fZyPNi/w5TpbTkAF/90bxC49xuMN+/s= X-MC-Unique: 0M19v0LSPm29LaTiq2M6qA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 04/13] crypto: Fix memory leaks in set_loaded for tls-* Date: Fri, 29 Jan 2021 17:10:53 +0000 Message-Id: <20210129171102.4109641-5-berrange@redhat.com> In-Reply-To: <20210129171102.4109641-1-berrange@redhat.com> References: <20210129171102.4109641-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , qemu-block@nongnu.org, libvir-list@redhat.com, Max Reitz , Gerd Hoffmann , Paolo Bonzini 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.13 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) From: Kevin Wolf If you set the loaded property to true when it was already true, the state is overwritten without freeing the old state first. Change the set_loaded callback so that it always frees the old state (which is a no-op if nothing was loaded) and only then load if requestsd. Signed-off-by: Kevin Wolf Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/tlscredsanon.c | 3 +-- crypto/tlscredspsk.c | 3 +-- crypto/tlscredsx509.c | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/crypto/tlscredsanon.c b/crypto/tlscredsanon.c index 30275b6847..bea5f76c55 100644 --- a/crypto/tlscredsanon.c +++ b/crypto/tlscredsanon.c @@ -123,10 +123,9 @@ qcrypto_tls_creds_anon_prop_set_loaded(Object *obj, { QCryptoTLSCredsAnon *creds =3D QCRYPTO_TLS_CREDS_ANON(obj); =20 + qcrypto_tls_creds_anon_unload(creds); if (value) { qcrypto_tls_creds_anon_load(creds, errp); - } else { - qcrypto_tls_creds_anon_unload(creds); } } =20 diff --git a/crypto/tlscredspsk.c b/crypto/tlscredspsk.c index e26807b899..f5a31108d1 100644 --- a/crypto/tlscredspsk.c +++ b/crypto/tlscredspsk.c @@ -192,10 +192,9 @@ qcrypto_tls_creds_psk_prop_set_loaded(Object *obj, { QCryptoTLSCredsPSK *creds =3D QCRYPTO_TLS_CREDS_PSK(obj); =20 + qcrypto_tls_creds_psk_unload(creds); if (value) { qcrypto_tls_creds_psk_load(creds, errp); - } else { - qcrypto_tls_creds_psk_unload(creds); } } =20 diff --git a/crypto/tlscredsx509.c b/crypto/tlscredsx509.c index c89dd62435..dbadad4df2 100644 --- a/crypto/tlscredsx509.c +++ b/crypto/tlscredsx509.c @@ -694,10 +694,9 @@ qcrypto_tls_creds_x509_prop_set_loaded(Object *obj, { QCryptoTLSCredsX509 *creds =3D QCRYPTO_TLS_CREDS_X509(obj); =20 + qcrypto_tls_creds_x509_unload(creds); if (value) { qcrypto_tls_creds_x509_load(creds, errp); - } else { - qcrypto_tls_creds_x509_unload(creds); } } =20 --=20 2.29.2