Skip to content

fix: wrap CommandV allocations in try/finally to prevent memory leaks - #785

Open
Bolt4243 wants to merge 1 commit into
mpvnet-player:mainfrom
Bolt4243:fix/commandv-finally
Open

fix: wrap CommandV allocations in try/finally to prevent memory leaks#785
Bolt4243 wants to merge 1 commit into
mpvnet-player:mainfrom
Bolt4243:fix/commandv-finally

Conversation

@Bolt4243

Copy link
Copy Markdown

CommandV in MpvClient.cs allocated unmanaged memory via Marshal.AllocHGlobal but freed it outside a finally block. Any exception thrown mid-loop (e.g. from a subsequent Marshal.AllocHGlobal or Marshal.Copy call) would skip the free loop, leaking all previously allocated pointers as well as rootPtr.

This change wraps the allocation loop and the mpv_command call in a try block, with the free loop moved into the corresponding finally block. The per-pointer free also guards against IntPtr.Zero to safely skip slots that were never allocated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant