Skip to content

Commit

Permalink
Improved com wrapper release in VBENativeServices in case of exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
MDoerner committed Jun 15, 2018
1 parent 9745875 commit 6ac12aa
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions Rubberduck.VBEEditor/Events/VBENativeServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,27 @@ private static ICodePane GetCodePaneFromHwnd(IntPtr hwnd)
var caption = hwnd.GetWindowText();
using (var panes = _vbe.CodePanes)
{
var foundIt = false;
foreach (var pane in panes)
{
using (var window = pane.Window)
try
{
if (window.Caption.Equals(caption))
using (var window = pane.Window)
{
return pane;
if (window.Caption.Equals(caption))
{
foundIt = true;
return pane;
}
}
}
finally
{
if(!foundIt)
{
pane.Dispose();
}
}
pane.Dispose();
}

return null;
Expand All @@ -243,13 +254,25 @@ private static IWindow GetWindowFromHwnd(IntPtr hwnd)
var caption = hwnd.GetWindowText();
using (var windows = _vbe.Windows)
{
var foundIt = false;
foreach (var window in windows)
{
if (window.Caption.Equals(caption))
try
{
return window;
if (window.Caption.Equals(caption))
{
foundIt = true;
return window;
}

}
finally
{
if (!foundIt)
{
window.Dispose();
}
}
window.Dispose();
}
return null;
}
Expand Down

0 comments on commit 6ac12aa

Please sign in to comment.