From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Thiago Melo Newsgroups: gmane.emacs.bugs Subject: bug#63589: [PATCH] 29.0.91; crash after creating graphical frames via emacsclient when compiled with cairo-xcb Date: Wed, 24 May 2023 11:54:30 +0000 Message-ID: References: <871qj9246a.fsf@yahoo.com> <83o7mdrc3y.fsf@gnu.org> <83bkidr37i.fsf@gnu.org> <87wn11yyi4.fsf@yahoo.com> <87edn9ytbo.fsf@yahoo.com> <835y8kr5re.fsf@gnu.org> <87pm6sy5rb.fsf@yahoo.com> <83wn10ppa1.fsf@gnu.org> <874jo3yjly.fsf@yahoo.com> <837cszp9cc.fsf@gnu.org> <87cz2rw8pz.fsf@yahoo.com> <83y1lfnqwb.fsf@gnu.org> <87y1lfuqyb.fsf@yahoo.com> <83wn0znn7j.fsf@gnu.org> <87lehevaqz.fsf@yahoo.com> <83r0r6o3zk.fsf@gnu.org> <87edn6v2v3.fsf@yahoo.com> <83h6s2ng1p.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7173"; mail-complaints-to="usenet@ciao.gmane.io" Cc: luangruo@yahoo.com, 63589@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed May 24 13:56:18 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q1n6I-0001aW-JK for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 24 May 2023 13:56:18 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q1n64-0002rj-KK; Wed, 24 May 2023 07:56:04 -0400 Original-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 1q1n62-0002rD-FN for bug-gnu-emacs@gnu.org; Wed, 24 May 2023 07:56:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q1n62-0001vn-86 for bug-gnu-emacs@gnu.org; Wed, 24 May 2023 07:56:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q1n62-0002IL-4N for bug-gnu-emacs@gnu.org; Wed, 24 May 2023 07:56:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Thiago Melo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 24 May 2023 11:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63589 X-GNU-PR-Package: emacs Original-Received: via spool by 63589-submit@debbugs.gnu.org id=B63589.16849293168610 (code B ref 63589); Wed, 24 May 2023 11:56:02 +0000 Original-Received: (at 63589) by debbugs.gnu.org; 24 May 2023 11:55:16 +0000 Original-Received: from localhost ([127.0.0.1]:42403 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q1n5I-0002Eo-1c for submit@debbugs.gnu.org; Wed, 24 May 2023 07:55:16 -0400 Original-Received: from mail-yw1-f172.google.com ([209.85.128.172]:62856) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q1n5F-0002EZ-IF for 63589@debbugs.gnu.org; Wed, 24 May 2023 07:55:14 -0400 Original-Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-561b7729a12so87045197b3.1 for <63589@debbugs.gnu.org>; Wed, 24 May 2023 04:55:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684929308; x=1687521308; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=xSMfRtjSm0EdGpjZ4kxSVcHE+I8m2+i1rvWfRYeujvs=; b=ffU+j9GyeN7FK0P6HjCOvFzp3GkYQ0+2BBopi3qiqScOZZwBIU+FCfk3g/7VA2ixfL qxOxOGNSR5ItzV61IzADcU/KL8L03Dq1s0i6u3IOEAmq0PxJeQKZrK+4QXva4vivgk/l fpnUY4VXb25B2lepVVNIO5tqt8XYVYR0j9UaP2Z2NtqkgkuQxAp4j0LeO1ugQez0rnSn 4b2jUBnFaiRvvRsCI5mgi+x82K45vYln+Pjlqk8ZsSoNWyyYhdNrSHkdaSNafiIPsAsy 7oGzVmC4tT1HZS6aFTqOlUqQg8qRMs70/CxO3Qu2Zh/Gl9THHLOBM7BcE8vrZpeFtstO ZevA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684929308; x=1687521308; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xSMfRtjSm0EdGpjZ4kxSVcHE+I8m2+i1rvWfRYeujvs=; b=C7LHFHNoLEwDNJIORrsFf8OCZOCC6xcuHo5OVQR2p/Trqn4o2f3H2abmDbvosd7Uet 5tl1mPhNMF4LcQoRfcu6nFgHkmTNRu87w+4tkqz2h/iKbvc6IFpUR4BaTqs1UhRdLQHp sP9Xg/mvUge6RFkwQb10EaNf3J8DGwpPAGTwM2qCSzmnzqada7YYg9Lxiph3aqRkC1oZ EZ1B2Sa5eTZ3aW0q8UnHviVha7mGDlX49SzqqdLywIk3onGI8RPkdIzimzwJ2VcjEP7i HETLeiZZ+lK+yAYun2vJFa6pDmCRbE+/XqycLOtObjYnt5zxcb/4ueyHOQpfqk/64jsl p4Fw== X-Gm-Message-State: AC+VfDyJGltBGm6THx1Z87ZAVa3W9s+Xycyr/Bqw3J4o5lCHihGLb4Al BiBowhXCxR00hxZpa+ZK5SyZF5iimneMAG1LvT0= X-Google-Smtp-Source: ACHHUZ5p5J8u3GXxUKt+FeKFttTFrF6/t7/BbUxjVXsTWGVvt2M5grT2aT+XMK9Qs3A5b0u8n3xah8/GZtQhCvCy2tg= X-Received: by 2002:a25:d2c2:0:b0:ba7:8562:33b8 with SMTP id j185-20020a25d2c2000000b00ba7856233b8mr19405241ybg.15.1684929307854; Wed, 24 May 2023 04:55:07 -0700 (PDT) In-Reply-To: <83h6s2ng1p.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:262290 Archived-At: > What triggers the bug with Lucid and GTK builds? the patch you > proposed or calls to delete-terminal? If the latter, then this is a > separate issue, and at least the Cairo-xcb build will behave like the > other builds in that scenario. Right? Sorry for not being clear. I meant calls to `delete-terminal', when Emacs is built with Cairo-XCB, and regardless of the toolkit. It's a similar scenario to trigger the bug: launch Emacs daemon, open one or more graphical frames, call the elisp function`delete-terminal' (all graphical frames and the display are closed because of it), open a new graphical frame... My last patch doesn't fix it because it only works when `(delete-frame)' is called instead. This situation is specific for toolkitless + Cairo-XCB Emacs, since here it ends up calling `x_delete_terminal' -> `XCloseDisplay'. Other toolkits don't call `x_delete_terminal' here, due to the logic at `delete_frame'. I hope I was more clear this time. My opinion is that it's all the same issue, which boils down to Cairo-XCB requiring more manual memory management than Cairo-XLib by design or limitation. I think we should really consider the approach from my first patch, which is ensuring that the Cairo-XCB device is cleaned up before calling XCloseDisplay. Everything else is a workaround. If the patch is considered too unsafe or too big, then we must clarify the specifics of what makes it so, so the matter can be addressed in a better way. Here's another patch, similar to the first one, but it only acts at `x_delete_terminal', and without storing global references. The strategy is similar to the one used at `ftcrfont_get_default_font_options'. It creates a dummy pixmap, then a dummy cairo xcb surface from it, then it extracts the cairo device from the surface, and then cleans up them all. #+begin_src diff --- a/src/xterm.c 2023-05-24 12:42:14.873824624 +0200 +++ b/src/xterm.c 2023-05-24 13:45:23.798382193 +0200 @@ -30841,6 +30841,30 @@ closing all the displays. */ XrmDestroyDatabase (dpyinfo->rdb); #endif +#ifdef USE_CAIRO_XCB_SURFACE + /* Ensure that the cairo device is destroyed before closing + connection (Bug#63589). For that, we create a drawable, an XCB + surface for that drawable, and then we get the device reference + from there. */ + + Pixmap drawable; + cairo_surface_t *surface; + + drawable = XCreatePixmap (dpyinfo->display, dpyinfo->root_window, + 1, 1, dpyinfo->n_planes); + surface = cairo_xcb_surface_create (dpyinfo->xcb_connection, drawable, + dpyinfo->xcb_visual, 1, 1); + + if (cairo_surface_status (surface) == CAIRO_STATUS_SUCCESS) + { + cairo_device_t *cairo_device; + cairo_device = cairo_device_reference (cairo_surface_get_device (surface)); + cairo_surface_destroy (surface); + cairo_device_finish (cairo_device); + cairo_device_destroy (cairo_device); + } + XFreePixmap (dpyinfo->display, drawable); +#endif #ifdef USE_GTK xg_display_close (dpyinfo->display); #else #+end_src