GDScript scripts that reference themselves leak at exit (GDScriptLanguage::finish stops early)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 30/100
調査の方向性
Read GDScriptLanguage::finish() and GDScript::clear() in the engine source, then compare Redot’s clear() with the linked Godot fix and Redot pull request #8. Reproduce the shutdown leak with the attached MRP and run the unit suite. Done when the leak no longer appears for the repro and the unit suite passes.
索引モデルが issue の本文から書いたものです。
説明
Tested versions
- Reproducible in: v26.3.stable.official [85e520394]
- Also reproducible in an unmodified local build of the same commit.
- Upstream Godot fixed the same bug for 4.7 in godotengine/godot#117991 (issue godotengine/godot#117975). Redot does not have that change yet.
System information
Windows 10 Pro 22H2 (build 19045), x86-64. Reproduced headless (--headless --audio-driver Dummy), so the GPU and renderer are not involved.
Issue description
A project can print these at exit even though it does nothing wrong:
WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
ERROR: 1 resources still in use at exit (run with --verbose for details).
With --verbose the resource is a GDScript, for example Resource still in use: res://holder.gd (GDScript).
Which scripts leak. The leaked script references itself:
- a class that names itself in its own code (
return Holder.new(), orHolder.g()insideclass_name Holder); - or a class that reads its own
static varfrom a function.
Why it comes and goes. It depends on load order, so the leak appears and disappears as unrelated code changes. In a game project it looked like random leaks after each refactor.
Cause. At shutdown, GDScriptLanguage::finish() walks script_list and calls clear() on each script to break those self-references. Each iteration:
- holds the current script in a local
Ref; - clears it;
- moves to the next list node;
- and only then releases the
Ref.
If that Ref was the last one, the script is freed together with its base script. New scripts are added at the front of the list, so a base loaded just before its subclass is exactly the next node. The loop then continues from a freed node, which is a use-after-free. On Windows it usually just stops early, so every script after that point is never cleared and the self-referencing ones leak.
Godot found the same use-after-free with ThreadSanitizer (godotengine/godot#117975) and fixed it in godotengine/godot#117991 by releasing the base script inside GDScript::clear().
Fix available. A Redot version of that fix, for 26.3-stable, is in dominicbytes/redot-engine#8 (single commit e45ed70). Redot's clear() still uses the older ClearData code, so the change goes in the root branch, and it also clears the raw _base pointer that Godot no longer has.
Results:
- This repro: leaks in 5 of 5 runs on the official build, and 0 of 10 with the fix.
- Unit tests: the full suite passes with the fix, 1346 of 1346.
Steps to reproduce
- Create the MRP below.
- Import it once:
redot --headless --path <mrp> --import. - Run it:
redot --headless --audio-driver Dummy --path <mrp>. The main scene quits in_ready(). - The leak warning and error print at exit on every run. Add
--verboseto seeres://holder.gdnamed.
Minimal reproduction project (MRP)
Bugsquad edit:
[!NOTE]
The order in whichmain.gdnamesScreenand thenConfirmmatters; swapping it, or makingConfirmusenew()instead ofConfirm.new(), hides the leak.
gdscript-shutdown-leak-mrp.zip
- 主要言語
- C++
- スター
- 6.1k
- フォーク
- 337
- 平均マージ
- 5日 8時間
- マージ済み PR(30日)
- 13
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Redot-Engine/redot-engine のほかの issue
-
enhancement topic:dotnet usability
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
Redot-Engine/redot-engine#1589 ·
メンテナーはふだん 1 日以内に返信
-
bug topic:gdscript
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
Redot-Engine/redot-engine#1588 ·
メンテナーはふだん 1 日以内に返信
-
Handle stateful audio effects when a bus channel becomes inactive対応中かも @GeneralProtectionFault が 27 日前に担当しました。 オープン
Redot-Engine/redot-engine#1584 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
bug usability
難易度 3/5 1〜2日 初心者へのやさしさ 53/100
Redot-Engine/redot-engine#1583 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug confirmed topic:3d topic:rendering
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
Redot-Engine/redot-engine#1568 ·
メンテナーはふだん 1 日以内に返信
Redot-Engine/redot-engine の issue をすべて見る
似ている issue
-
Make the HTTP server's keep-alive and headers timeouts configurable対応中かも @mattgodbolt が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
compiler-explorer/compiler-explorer#9902 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Nixtla/statsforecast#1371 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
[Bug]: pip install -U cudaq-qec fails with a conflict that names cudaq-qec itself対応中かも @fedonman が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
task
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
SparseLinearAlgebra/spla#316 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信