Skip to content

Return a copy of installedmods, enginebuilds and modtools instead of references (C4 fix)#373

Merged
Shivansps merged 1 commit intoKnossosNET:mainfrom
Shivansps:do-not-return-list-references
Apr 12, 2026
Merged

Return a copy of installedmods, enginebuilds and modtools instead of references (C4 fix)#373
Shivansps merged 1 commit intoKnossosNET:mainfrom
Shivansps:do-not-return-list-references

Conversation

@Shivansps
Copy link
Copy Markdown
Member

File: Knossos.NET/Classes/Knossos.cs:25-27

private static List<Mod> installedMods = new List<Mod>();
private static List<FsoBuild> engineBuilds = new List<FsoBuild>();
private static List<Tool> modTools = new List<Tool>();

These are accessed from multiple threads (UI, background tasks, Nebula loading, install tasks) with zero synchronization -- there are no lock statements anywhere in the codebase. GetInstalledModList(null) and GetInstalledBuildsList() return the raw list references, allowing callers to mutate them (e.g., App.axaml.cs calls mods.Sort() on the shared list). Concurrent read+write on List<T> causes InvalidOperationException, IndexOutOfRangeException, or silent corruption.

This should be enoght to make sure it cant happen, when the entire list is returned, a copy is sent instead of a reference.

@Shivansps Shivansps added the fix Fix for a bug label Apr 10, 2026
@Shivansps Shivansps merged commit 16a25dd into KnossosNET:main Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Fix for a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants