From nobody Wed May 15 02:58:04 2024 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=1621268000; cv=none; d=zohomail.com; s=zohoarc; b=cJyQY5gG6r6PJnu8KuMM9l4vRdRZ1GHKb4L/1CV1qUQzc57INNUGV6eVnkX+6kx5En8v+ISD3WMIIfYulz8cOr2dhm9NXualzlV1Ud7C4oKZcgJ70UP2ndyFjThuHvjmmQNqHT0ERM9OXqrQEKdNHfB5Akx5AQT0Kw0so7RLZCs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621268000; 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=nx94hi+UQhDyMUNbTwf+W6ITkAktz/kaP4Cgwec49Dc=; b=cgmFER5f0wCjxvuZAAIb2D3MAPrD23PjFsuLl/4xYT/j1pIRzoml4GOojpM1HD0IO2nKYLEP9aQNGku/HDleXADKC2DvVhSt6wGW3+aD7/b+DlXHnFdpICSU5EWW7aS8kmMwMy0lpHfFyjNkOTOBE3CqOAnZLblhl/8+cLUwJZs= 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 1621268000430329.953055231324; Mon, 17 May 2021 09:13:20 -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-339-NAeM7E8VO7KfjEZYDV3sAw-1; Mon, 17 May 2021 12:13:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C83918015DB; Mon, 17 May 2021 16:13:09 +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 6FB6E5D6D7; Mon, 17 May 2021 16:13:08 +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 C395355347; Mon, 17 May 2021 16:13:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14HGD5oK002553 for ; Mon, 17 May 2021 12:13:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4F6DF1F421; Mon, 17 May 2021 16:13:05 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id C62482BCD0 for ; Mon, 17 May 2021 16:13:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621267998; 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=nx94hi+UQhDyMUNbTwf+W6ITkAktz/kaP4Cgwec49Dc=; b=FLz2+/0Q/tcCt/KSps3fgYG3eLVg8kLhEedpt8v6KLHmgpD5Q2TfvHm6z+Tzf20Uxvc6qQ 8qaNWxWVLDKe8dRiIWGJyzwwMFE647ch7YCKopZVVnQCGINkgzLdirVKjCOF/FlRM/z5sp NDOC+MP90+SdMIXgzdcP8WcjWCmUvP4= X-MC-Unique: NAeM7E8VO7KfjEZYDV3sAw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] viridentity: Fix ref/unref imbalance in VIR_IDENTITY_AUTORESTORE Date: Mon, 17 May 2021 18:12:56 +0200 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.15 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" The basic use case of VIR_IDENTITY_AUTORESTORE() is in conjunction with virIdentityElevateCurrent(). What happens is that virIdentityElevateCurrent() gets current identity (which increases the refcounter of thread local virIdentity object) and returns a pointer to it. Later, when the variable goes out of scope the virIdentityRestoreHelper() is called which calls virIdentitySetCurrent() over the old identity. But this means that the refcounter is increased again. Therefore, we have to explicitly decrease the refcounter by calling g_object_unref(). Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 --- I've observed this imbalance whilst running qemuxml2argvtest under valgrind: =3D=3D10412=3D=3D 949 (40 direct, 909 indirect) bytes in 1 blocks are defin= itely lost in loss record 524 of 539 =3D=3D10412=3D=3D at 0x48397EF: malloc (vg_replace_malloc.c:307) =3D=3D10412=3D=3D by 0x50806F8: g_malloc (in /usr/lib64/libglib-2.0.so.0= .6600.7) =3D=3D10412=3D=3D by 0x50992FD: g_slice_alloc (in /usr/lib64/libglib-2.0= .so.0.6600.7) =3D=3D10412=3D=3D by 0x50999B9: g_slice_alloc0 (in /usr/lib64/libglib-2.= 0.so.0.6600.7) =3D=3D10412=3D=3D by 0x518D9AB: g_type_create_instance (in /usr/lib64/li= bgobject-2.0.so.0.6600.7) =3D=3D10412=3D=3D by 0x51739DC: g_object_new_internal (in /usr/lib64/lib= gobject-2.0.so.0.6600.7) =3D=3D10412=3D=3D by 0x5174F5C: g_object_new_with_properties (in /usr/li= b64/libgobject-2.0.so.0.6600.7) =3D=3D10412=3D=3D by 0x5175978: g_object_new (in /usr/lib64/libgobject-2= .0.so.0.6600.7) =3D=3D10412=3D=3D by 0x496C3C6: virIdentityNew (viridentity.c:407) =3D=3D10412=3D=3D by 0x496BF1A: virIdentityGetSystem (viridentity.c:318) =3D=3D10412=3D=3D by 0x117CEF: testCompareXMLToArgv (qemuxml2argvtest.c:= 653) =3D=3D10412=3D=3D by 0x148505: virTestRun (testutils.c:142) Test #315 doesn't tickle the bug, while test #316 does. src/util/viridentity.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util/viridentity.c b/src/util/viridentity.c index e7e5c31241..eb77f69e2e 100644 --- a/src/util/viridentity.c +++ b/src/util/viridentity.c @@ -197,8 +197,12 @@ void virIdentityRestoreHelper(virIdentity **identptr) { virIdentity *ident =3D *identptr; =20 - if (ident !=3D NULL) + if (ident !=3D NULL) { virIdentitySetCurrent(ident); + /* virIdentitySetCurrent() grabs its own reference. + * We don't need ours anymore. */ + g_object_unref(ident); + } } =20 #define TOKEN_BYTES 16 --=20 2.26.3