From b062fc056fab72e6fb91f17f805f6f341f8b4dd0 Mon Sep 17 00:00:00 2001 From: VictoriousRaptor <10308169+VictoriousRaptor@users.noreply.github.com> Date: Fri, 2 Jan 2026 12:23:05 +0800 Subject: [PATCH] Catch exceptions and release com objects --- .../Programs/ShellLocalization.cs | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/ShellLocalization.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/ShellLocalization.cs index 6f2118af8..815b74b96 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Programs/ShellLocalization.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/ShellLocalization.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Runtime.InteropServices; using Windows.Win32; using Windows.Win32.Foundation; @@ -25,12 +26,22 @@ namespace Flow.Launcher.Plugin.Program.Programs return string.Empty; } - PWSTR displayName; - shellItem.GetDisplayName(Windows.Win32.UI.Shell.SIGDN.SIGDN_NORMALDISPLAY, &displayName); - string filename = displayName.ToString(); - PInvoke.CoTaskMemFree(displayName); - - return filename; + try + { + PWSTR displayName; + shellItem.GetDisplayName(Windows.Win32.UI.Shell.SIGDN.SIGDN_NORMALDISPLAY, &displayName); + string filename = displayName.ToString(); + PInvoke.CoTaskMemFree(displayName); + return filename; + } + catch + { + return string.Empty; + } + finally + { + Marshal.ReleaseComObject(shellItem); + } } ///