From nobody Sat Feb 7 08:13:52 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1678811161; cv=none; d=zohomail.com; s=zohoarc; b=m2qzRbOT3K9XNNW9vHvg5H2Dc3i4CzlrlpdHPqubH6Jx3ELAqOBuzo6uqpYozt379lTY34mMUXdo6xyd2JpVOxg59NHzKec0GruQYptq1daP51R4Q7hwLJ28Ilznku4qlvMgpSj531x0GQgbOgxK5pWv1bJYYFbRJnbC/nu6VWU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678811161; 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=urFW4nSraIsPDPq4iZZOOIlcOzIvdO91+DoMI1iB4bE=; b=M7Bg/dL/+934au02SBo1RCS8DngBKR9q1/aEdT4Av3KDFKgACplKOIXKpy9I9VuFHdhTGleEAdtWpwS75QWlZz5ixGujua8yYdeHm5o/RW4cbYBjxtAZR2kE1VmLXM780FpZxksGFHllk55EvdjhnfC2++ROf8sbuU8aHn8ZFr8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1678811161112918.80965547421; Tue, 14 Mar 2023 09:26:01 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-138-XkvRTHwGMlCOO5G7dLQYjQ-1; Tue, 14 Mar 2023 12:25:55 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7C4FE1C27D81; Tue, 14 Mar 2023 16:25:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 690E74042AC3; Tue, 14 Mar 2023 16:25:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 593DF19465A2; Tue, 14 Mar 2023 16:25:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DB19819465A0 for ; Tue, 14 Mar 2023 16:25:50 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id CB54D4042AC4; Tue, 14 Mar 2023 16:25:50 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id A36824042AC2; Tue, 14 Mar 2023 16:25:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678811160; 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=urFW4nSraIsPDPq4iZZOOIlcOzIvdO91+DoMI1iB4bE=; b=PlOpogtF4mh4RudqKomN8tBnZVMfifnb8T3uDz81SliLLJ36KYTnnaBCHFdM3kr8QctXlT 8QJ9VZhV125z2kB6tpxtfGwcv0vgo+ddGdYlnEZmb5pVg0/iKkXE7KZuMMQvR2z/+FeUCJ 0/73MRJKC3cPfIuYmsgleQCqMslP+iw= X-MC-Unique: XkvRTHwGMlCOO5G7dLQYjQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 3/3] io/channel-tls: plug memory leakage on GSource Date: Tue, 14 Mar 2023 16:25:40 +0000 Message-Id: <20230314162540.385954-4-berrange@redhat.com> In-Reply-To: <20230314162540.385954-1-berrange@redhat.com> References: <20230314162540.385954-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Matheus Tavares Bernardino , qemu-block@nongnu.org, libvir-list@redhat.com, Peter Lieven , Markus Armbruster , Hanna Reitz , Gerd Hoffmann , Ronnie Sahlberg , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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) X-ZM-MESSAGEID: 1678811162491100002 From: Matheus Tavares Bernardino This leakage can be seen through test-io-channel-tls: $ ../configure --target-list=3Daarch64-softmmu --enable-sanitizers $ make ./tests/unit/test-io-channel-tls $ ./tests/unit/test-io-channel-tls Indirect leak of 104 byte(s) in 1 object(s) allocated from: #0 0x7f81d1725808 in __interceptor_malloc ../../../../src/libsanitizer/= asan/asan_malloc_linux.cc:144 #1 0x7f81d135ae98 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0= x57e98) #2 0x55616c5d4c1b in object_new_with_propv ../qom/object.c:795 #3 0x55616c5d4a83 in object_new_with_props ../qom/object.c:768 #4 0x55616c5c5415 in test_tls_creds_create ../tests/unit/test-io-channe= l-tls.c:70 #5 0x55616c5c5a6b in test_io_channel_tls ../tests/unit/test-io-channel-= tls.c:158 #6 0x7f81d137d58d (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x7a58d) Indirect leak of 32 byte(s) in 1 object(s) allocated from: #0 0x7f81d1725a06 in __interceptor_calloc ../../../../src/libsanitizer/= asan/asan_malloc_linux.cc:153 #1 0x7f81d1472a20 in gnutls_dh_params_init (/lib/x86_64-linux-gnu/libgn= utls.so.30+0x46a20) #2 0x55616c6485ff in qcrypto_tls_creds_x509_load ../crypto/tlscredsx509= .c:634 #3 0x55616c648ba2 in qcrypto_tls_creds_x509_complete ../crypto/tlscreds= x509.c:694 #4 0x55616c5e1fea in user_creatable_complete ../qom/object_interfaces.c= :28 #5 0x55616c5d4c8c in object_new_with_propv ../qom/object.c:807 #6 0x55616c5d4a83 in object_new_with_props ../qom/object.c:768 #7 0x55616c5c5415 in test_tls_creds_create ../tests/unit/test-io-channe= l-tls.c:70 #8 0x55616c5c5a6b in test_io_channel_tls ../tests/unit/test-io-channel-= tls.c:158 #9 0x7f81d137d58d (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x7a58d) ... SUMMARY: AddressSanitizer: 49143 byte(s) leaked in 184 allocation(s). The docs for `g_source_add_child_source(source, child_source)` says "source will hold a reference on child_source while child_source is attached to it." Therefore, we should unreference the child source at `qio_channel_tls_read_watch()` after attaching it to `source`. With this change, ./tests/unit/test-io-channel-tls shows no leakages. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Matheus Tavares Bernardino Signed-off-by: Daniel P. Berrang=C3=A9 --- io/channel-tls.c | 1 + 1 file changed, 1 insertion(+) diff --git a/io/channel-tls.c b/io/channel-tls.c index 8052945ba0..5a7a3d48d6 100644 --- a/io/channel-tls.c +++ b/io/channel-tls.c @@ -446,6 +446,7 @@ qio_channel_tls_read_watch(QIOChannelTLS *tioc, GSource= *source) object_ref(OBJECT(tioc)); =20 g_source_add_child_source(source, child); + g_source_unref(child); } =20 static GSource *qio_channel_tls_create_watch(QIOChannel *ioc, --=20 2.39.2