Skip to content

Commit 2d21a7b

Browse files
committed
[SHELL] Fix a leak
1 parent 32f3a56 commit 2d21a7b

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

Source/KNSoft.MakeLifeEasier/Shell/VirtDesk.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Shell_EnumVirtualDesktops(
139139
{
140140
HRESULT hr;
141141
IObjectArray* Desktops;
142-
UINT Count;
142+
UINT Count, i;
143143
IVirtualDesktop* Desktop;
144144

145145
if (!IS_NT_VERSION_GE(NT_VERSION_WIN11_24H2))
@@ -154,21 +154,23 @@ Shell_EnumVirtualDesktops(
154154
hr = Desktops->lpVtbl->GetCount(Desktops, &Count);
155155
if (FAILED(hr))
156156
{
157-
return hr;
157+
goto _Exit;
158158
}
159-
for (UINT i = 0; i < Count; i++)
159+
for (i = 0; i < Count; i++)
160160
{
161161
hr = Desktops->lpVtbl->GetAt(Desktops, i, &IID_IVirtualDesktop, &Desktop);
162-
if (SUCCEEDED(hr))
162+
if (FAILED(hr))
163163
{
164-
if (!Callback(Desktop, i, Context))
165-
{
166-
return S_FALSE;
167-
}
168-
} else
164+
goto _Exit;
165+
}
166+
if (!Callback(Desktop, i, Context))
169167
{
170-
return hr;
168+
hr = S_FALSE;
169+
goto _Exit;
171170
}
172171
}
173-
return S_OK;
172+
173+
_Exit:
174+
Desktops->lpVtbl->Release(Desktops);
175+
return hr;
174176
}

0 commit comments

Comments
 (0)