Skip to content

[MEDIUM] ScriptableObject default diff leaks temporary instance on serialization failure #128

Description

@Daliys

Problem

diff_scriptable_object_against_defaults creates a temporary ScriptableObject instance and only destroys it after the diff loop completes successfully.

Evidence

  • Editor/MCPServerMethods.ScriptableObject.cs:30 creates defaults = ScriptableObject.CreateInstance(so.GetType()).
  • Editor/MCPServerMethods.ScriptableObject.cs:36-54 serializes and compares properties.
  • Editor/MCPServerMethods.ScriptableObject.cs:56 destroys defaults, but this is not inside a finally.

Impact

If property serialization/comparison throws, the temporary ScriptableObject remains alive until domain reload. Repeated failing calls can accumulate hidden objects.

Suggested fix

Wrap the diff loop in try/finally and call DestroyImmediate(defaults) in the finally when the instance was created.

Source report

Imported from audit report item: resource-leak (9) / Editor/MCPServerMethods.ScriptableObject.cs:56.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageImported or reported issue awaiting owner reviewpriority: mediumImportant defect or workflow gap with workaroundsurface: scriptable-objectScriptableObject read, update, diff, and asset workflowssurface: unity-editorUnity Editor package, windows, menus, or C# server surfacetype: resource-leakProcess, stream, handle, or lifecycle leak/hang risk

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions