Skip to content

Windows: release the drop data medium - #379

Open
cjbhaines wants to merge 1 commit into
RustAudio:masterfrom
cjbhaines:fix/windows-drop-medium-release
Open

cjbhaines wants to merge 1 commit into
RustAudio:masterfrom
cjbhaines:fix/windows-drop-medium-release

Conversation

@cjbhaines

Copy link
Copy Markdown

While reading through the Windows drop target I noticed that parse_drop_data never releases the STGMEDIUM it gets back from IDataObject::GetData. GetData hands ownership of the medium to the caller, so it's up to us to call ReleaseStgMedium, and the windows crate's STGMEDIUM doesn't do that on drop. So every DragEnter and Drop leaks whatever the source handed over: the HGLOBAL with the file list, or a reference to the source's pUnkForRelease object.

The fix makes the medium mutable and calls ReleaseStgMedium once the paths have been read, and on the early return when there are no files. If GetData fails there's no medium, so that path stays as it is. ReleaseStgMedium is already covered by the existing windows features, so Cargo.toml is unchanged.

Tests: I added two Windows tests in src/platform/win/drop_target.rs. They create a hidden window with a drop target, plus a small test IDataObject that hands out a new medium on every GetData call, with a pUnkForRelease object that keeps count of the media that haven't been released yet. Each test runs a DragEnter and a Drop through the drop target, one with a single file and one with no files, and checks that nothing is left unreleased. Both fail on master (one medium left after DragEnter, two after Drop) and pass with the fix. It doesn't touch any of the files in #377 or #378, so the three don't depend on each other.

IDataObject::GetData hands ownership of the returned STGMEDIUM to the
caller, but parse_drop_data never released it, so every DragEnter and
Drop leaked the source's HGLOBAL (or its pUnkForRelease reference).
Release it once the paths have been read, and on the zero-file early
return too.
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