Undisposed resource problem in the generated codes

オープン 初心者向け
#582 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
csharp
領域
tooling

調査の方向性

提供されたコマンド LottieGen -Language CSharp -Public -WinUIVersion 3.0 -InputFile Item.json を使用して LottieGen のエントリ ポイントから始め、生成された EffectFactory() コードがどこで出力されるかを確認します。C# の出力を再生成し、返される factory や brush の動作を変更せずに、factory の作成後に CompositeEffect が破棄されることを確認します。CodeQL のリソース警告が解決されるはずです。

索引モデルが issue の本文から書いたものです。

説明

This is part of the generated code

   CompositionEffectFactory EffectFactory()
   {
       var compositeEffect = new CompositeEffect();
       compositeEffect.Mode = CanvasComposite.DestinationIn;
       compositeEffect.Sources.Add(new CompositionEffectSourceParameter("destination"));
       compositeEffect.Sources.Add(new CompositionEffectSourceParameter("source"));
       var result = _c.CreateEffectFactory(compositeEffect);
       return result;
   }

It is not using the using keyword for the CompositeEffect object being created, leaving undisposed resources. GitHub CodeQL scans also confirm this problem:

Image

The correct code would be this:

			CompositionEffectFactory EffectFactory()
			{
				using CompositeEffect compositeEffect = new();
				compositeEffect.Mode = CanvasComposite.DestinationIn;
				compositeEffect.Sources.Add(new CompositionEffectSourceParameter("destination"));
				compositeEffect.Sources.Add(new CompositionEffectSourceParameter("source"));
				var result = _c.CreateEffectFactory(compositeEffect);
				return result;
			}

Explanation

After CreateEffectFactory has created the CompositionEffectFactory, the code does not need the original CompositeEffect instance anymore. Disposing the local CompositeEffect after factory creation does not dispose the CompositionEffectFactory or the CompositionEffectBrush created from it. EffectBrush() creates the factory, creates a brush from it, sets the two source parameters, and returns the brush, so the CompositeEffect lifetime can end inside EffectFactory().

Details

  • .NET 10
  • Visual Studio latest version
  • LottieGen version: 8.2.250604.1
  • Command: LottieGen -Language CSharp -Public -WinUIVersion 3.0 -InputFile Item.json
主要言語
C#
スター
723
フォーク
79
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

CommunityToolkit/Lottie-Windows のほかの issue

CommunityToolkit/Lottie-Windows の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。