From nobody Sun Apr 12 00:54:37 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1772550448; cv=none; d=zohomail.com; s=zohoarc; b=kkA27jK+rOWEPYOOPeZMwfu5N4IDegkiZHV3Zk97eyOBNaRHWStWUW+KHi0uvXD1ph3Kx0CUtutDIVFysa9/j/qoQqaJf1R9OR3Frkmw9pnJARCMhMUt+zgh/Ocl1eZuYAOvQmFQaezngDt9YgrqDz6htJuHnDDrihVWGe4oOr8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772550448; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3x5dOLupVL+hjV4GsiegMaAvA6L4zY0/YDT1LJKlaPI=; b=k8BOTTGWBMkmkB76a+VpWiuoeYvzl76FanJfKYJh+Jy8wh3ScJbd0ELF6XsNULUp/ZgDMV/rdfiPG80GKYSBAvX8d8wCCZu4pdDx4xVOQ5N5OxFT5e0d4khsZyCVbrj1Z00h3sSRrt5hEQJZCJx30yy5aU4td33zbFDHQgwDakw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772550448299287.58678305251317; Tue, 3 Mar 2026 07:07:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxRKH-0006RQ-TR; Tue, 03 Mar 2026 10:06:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxRKG-0006Og-50 for qemu-devel@nongnu.org; Tue, 03 Mar 2026 10:06:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxRKE-00022w-AY for qemu-devel@nongnu.org; Tue, 03 Mar 2026 10:06:19 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-577-CbaMKYYAMSyw1z1EXn7YHA-1; Tue, 03 Mar 2026 10:06:16 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 88599180AED6 for ; Tue, 3 Mar 2026 15:06:15 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.225.185]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5610A1800348; Tue, 3 Mar 2026 15:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772550377; h=from:from: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; bh=3x5dOLupVL+hjV4GsiegMaAvA6L4zY0/YDT1LJKlaPI=; b=ijAL4c/uvnPS8kfsbhmYedX2fvX7dXByGGm/IPUWnuK/bknRMH0/fcwwqGBr+X7LBJv9Qw XwdksmUFCs8C/1pJ3Wp8l+y45q4vu7Cxw3aasnjg4O8AG8qbOnfH0nr764rJdbVbpguqgS rAN0ZDPBVY7qU3+QQJJ/Tyb1tyaqt/c= X-MC-Unique: CbaMKYYAMSyw1z1EXn7YHA-1 X-Mimecast-MFC-AGG-ID: CbaMKYYAMSyw1z1EXn7YHA_1772550375 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 04/27] io: fix cleanup for websock I/O source data on cancellation Date: Tue, 3 Mar 2026 15:05:41 +0000 Message-ID: <20260303150604.2402872-5-berrange@redhat.com> In-Reply-To: <20260303150604.2402872-1-berrange@redhat.com> References: <20260303150604.2402872-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.322, RCVD_IN_VALIDITY_SAFE_BLOCKED=1.141, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1772550450727154100 The websock code will create a GSource for tracking completion of the handshake process, passing a QIOTask which is freed by the callback when it completes, which means when a source is cancelled, nothing is free'ing the task. Switch to provide a data free callback to the GSource, which ensures the QIOTask is always freed even when the main event callback never fires. Fixes: https://gitlab.com/qemu-project/qemu/-/issues/3114 Signed-off-by: Daniel P. Berrang=C3=A9 --- io/channel-websock.c | 49 +++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/io/channel-websock.c b/io/channel-websock.c index 100faba6b3..9902b014f7 100644 --- a/io/channel-websock.c +++ b/io/channel-websock.c @@ -526,11 +526,32 @@ static int qio_channel_websock_handshake_read(QIOChan= nelWebsock *ioc, return 1; } =20 +typedef struct QIOChannelWebsockData { + QIOTask *task; +} QIOChannelWebsockData; + +static void qio_channel_websock_data_free(gpointer user_data) +{ + QIOChannelWebsockData *data =3D user_data; + /* + * Usually 'task' will be NULL since the GSource + * callback will either complete the task or pass + * it on to a new GSource. We'll see a non-NULL + * task here only if the GSource was released before + * its callback triggers + */ + if (data->task) { + qio_task_free(data->task); + } + g_free(data); +} + static gboolean qio_channel_websock_handshake_send(QIOChannel *ioc, GIOCondition condition, gpointer user_data) { - QIOTask *task =3D user_data; + QIOChannelWebsockData *data =3D user_data; + QIOTask *task =3D data->task; QIOChannelWebsock *wioc =3D QIO_CHANNEL_WEBSOCK( qio_task_get_source(task)); Error *err =3D NULL; @@ -545,7 +566,6 @@ static gboolean qio_channel_websock_handshake_send(QIOC= hannel *ioc, trace_qio_channel_websock_handshake_fail(ioc, error_get_pretty(err= )); qio_task_set_error(task, err); qio_task_complete(task); - qio_task_free(task); wioc->hs_io_tag =3D 0; return FALSE; } @@ -562,7 +582,6 @@ static gboolean qio_channel_websock_handshake_send(QIOC= hannel *ioc, trace_qio_channel_websock_handshake_complete(ioc); qio_task_complete(task); } - qio_task_free(task); wioc->hs_io_tag =3D 0; return FALSE; } @@ -574,7 +593,8 @@ static gboolean qio_channel_websock_handshake_io(QIOCha= nnel *ioc, GIOCondition condition, gpointer user_data) { - QIOTask *task =3D user_data; + QIOChannelWebsockData *data =3D user_data, *newdata =3D NULL; + QIOTask *task =3D data->task; QIOChannelWebsock *wioc =3D QIO_CHANNEL_WEBSOCK( qio_task_get_source(task)); Error *err =3D NULL; @@ -590,7 +610,6 @@ static gboolean qio_channel_websock_handshake_io(QIOCha= nnel *ioc, trace_qio_channel_websock_handshake_fail(ioc, error_get_pretty(err= )); qio_task_set_error(task, err); qio_task_complete(task); - qio_task_free(task); wioc->hs_io_tag =3D 0; return FALSE; } @@ -603,12 +622,14 @@ static gboolean qio_channel_websock_handshake_io(QIOC= hannel *ioc, error_propagate(&wioc->io_err, err); =20 trace_qio_channel_websock_handshake_reply(ioc); + newdata =3D g_new0(QIOChannelWebsockData, 1); + newdata->task =3D g_steal_pointer(&data->task); wioc->hs_io_tag =3D qio_channel_add_watch( wioc->master, G_IO_OUT, qio_channel_websock_handshake_send, - task, - NULL); + newdata, + qio_channel_websock_data_free); return FALSE; } =20 @@ -904,12 +925,12 @@ void qio_channel_websock_handshake(QIOChannelWebsock = *ioc, gpointer opaque, GDestroyNotify destroy) { - QIOTask *task; + QIOChannelWebsockData *data =3D g_new0(QIOChannelWebsockData, 1); =20 - task =3D qio_task_new(OBJECT(ioc), - func, - opaque, - destroy); + data->task =3D qio_task_new(OBJECT(ioc), + func, + opaque, + destroy); =20 trace_qio_channel_websock_handshake_start(ioc); trace_qio_channel_websock_handshake_pending(ioc, G_IO_IN); @@ -917,8 +938,8 @@ void qio_channel_websock_handshake(QIOChannelWebsock *i= oc, ioc->master, G_IO_IN, qio_channel_websock_handshake_io, - task, - NULL); + data, + qio_channel_websock_data_free); } =20 =20 --=20 2.53.0