From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by bl2.djc.id.au (Postfix, from userid 1000) id 38F9229BBD1; Sat, 17 Oct 2026 11:24:59 +1100 (AEDT) Date: Sat, 17 Oct 2026 11:25:04 +1100 To: sup-commits@supmua.dev Subject: [ncursesw-ruby.git] 06/10: add GC mark function for PANEL to mark userptr MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Reply-To: Dan Callaghan In-Reply-To: <179219669847.381480.6906705364727468632@bl2.djc.id.au> References: <179219669847.381480.6906705364727468632@bl2.djc.id.au> Thread-Index: AQAAEjRW1ch74naHRnKg4xL7js+6AQ== X-Git-Host: bl2.djc.id.au X-Git-Repo: ncursesw-ruby.git X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Rev: 412d8fc2a66d20da280daa2536dd53d57d1232fe X-Git-NotificationType: diff X-Git-Multimail-Version: 1.7.dev Auto-Submitted: auto-generated Message-Id: <20261017002459.38F9229BBD1@bl2.djc.id.au> From: Dan Callaghan List-Id: New commit on branch master: https://supmua.dev/git/ncursesw-ruby/commit/412d8fc2a66d20da280daa2536dd53d57d1232fe.html commit 412d8fc2a66d20da280daa2536dd53d57d1232fe Author: Dan Callaghan AuthorDate: Sat Oct 10 16:04:52 2026 +1100 add GC mark function for PANEL to mark userptr Otherwise a Ruby object saved in userptr may be garbage collected while it is still referenced by the PANEL, resulting in a user-after-free. --- panel_wrap.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/panel_wrap.c b/panel_wrap.c index 6cf350b..b702c52 100644 --- a/panel_wrap.c +++ b/panel_wrap.c @@ -29,8 +29,13 @@ VALUE mPanel; VALUE cPANEL; +static void panel_rb_mark(void * panel) { + const void * userptr = panel_userptr((PANEL*)panel); + if (userptr != NULL) rb_gc_mark((VALUE)userptr); +} static const struct rb_data_type_struct panel_rbtype = { .wrap_struct_name = "Ncurses::Panel::PANEL", + .function.dmark = panel_rb_mark, }; static VALUE wrap_panel(PANEL* panel) {