Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure COM interfaces are cleaned up on shutdown #948

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions packages/wm-platform/src/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,27 @@ impl ComInit {
}

/// Returns an instance of `IServiceProvider`.
pub fn service_provider(&self) -> anyhow::Result<IServiceProvider> {
pub fn service_provider(&self) -> anyhow::Result<&IServiceProvider> {
self
.service_provider
.clone()
.as_ref()
.context("Unable to create `IServiceProvider` instance.")
}

/// Returns an instance of `IApplicationViewCollection`.
pub fn application_view_collection(
&self,
) -> anyhow::Result<IApplicationViewCollection> {
self.application_view_collection.clone().context(
) -> anyhow::Result<&IApplicationViewCollection> {
self.application_view_collection.as_ref().context(
"Failed to query for `IApplicationViewCollection` instance.",
)
}

/// Returns an instance of `ITaskbarList2`.
pub fn taskbar_list(&self) -> anyhow::Result<ITaskbarList2> {
pub fn taskbar_list(&self) -> anyhow::Result<&ITaskbarList2> {
self
.taskbar_list
.clone()
.as_ref()
.context("Unable to create `ITaskbarList2` instance.")
}
}
Expand All @@ -96,6 +96,11 @@ impl Default for ComInit {

impl Drop for ComInit {
fn drop(&mut self) {
// Explicitly drop COM interfaces first.
drop(self.taskbar_list.take());
drop(self.application_view_collection.take());
drop(self.service_provider.take());

unsafe { CoUninitialize() };
}
}
Expand Down