Repository navigation
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While reading through the Windows drop target I noticed that
parse_drop_datanever releases theSTGMEDIUMit gets back fromIDataObject::GetData.GetDatahands ownership of the medium to the caller, so it's up to us to callReleaseStgMedium, and thewindowscrate'sSTGMEDIUMdoesn't do that on drop. So everyDragEnterandDropleaks whatever the source handed over: the HGLOBAL with the file list, or a reference to the source'spUnkForReleaseobject.The fix makes the medium mutable and calls
ReleaseStgMediumonce the paths have been read, and on the early return when there are no files. IfGetDatafails there's no medium, so that path stays as it is.ReleaseStgMediumis already covered by the existingwindowsfeatures, soCargo.tomlis 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 testIDataObjectthat hands out a new medium on everyGetDatacall, with apUnkForReleaseobject that keeps count of the media that haven't been released yet. Each test runs aDragEnterand aDropthrough 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 afterDragEnter, two afterDrop) 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.