Skip to content

Commit 2a0c79b

Browse files
authored
Null out host handle in OleInterfaces when disposing (#13532)
This was causing the AxHost's container to stay rooted.
1 parent bedb989 commit 2a0c79b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/System.Windows.Forms/System/Windows/Forms/ActiveX/AxHost.OleInterfaces.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private sealed unsafe class OleInterfaces :
2828
IDisposable,
2929
IManagedWrapper<IDispatch, IDispatchEx, IOleControlSite, IOleClientSite, IOleWindow, IOleInPlaceSite, ISimpleFrameSite, IVBGetControl, IGetVBAObject, IPropertyNotifySink>
3030
{
31-
private readonly AxHost _host;
31+
private AxHost _host;
3232
private ConnectionPointCookie? _connectionPoint;
3333

3434
internal OleInterfaces(AxHost host) => _host = host.OrThrowIfNull();
@@ -41,6 +41,9 @@ protected override void Dispose(bool disposing)
4141
{
4242
StopEvents();
4343
}
44+
45+
// If we don't null this out, this will indirectly root the container control.
46+
_host = null!;
4447
}
4548

4649
internal AxHost GetAxHost() => _host;
@@ -251,7 +254,7 @@ HRESULT IOleControlSite.Interface.ShowPropertyFrame()
251254
// IOleClientSite methods:
252255
HRESULT IOleClientSite.Interface.SaveObject() => HRESULT.E_NOTIMPL;
253256

254-
unsafe HRESULT IOleClientSite.Interface.GetMoniker(uint dwAssign, uint dwWhichMoniker, IMoniker** ppmk)
257+
HRESULT IOleClientSite.Interface.GetMoniker(uint dwAssign, uint dwWhichMoniker, IMoniker** ppmk)
255258
{
256259
if (ppmk is null)
257260
{
@@ -262,7 +265,7 @@ unsafe HRESULT IOleClientSite.Interface.GetMoniker(uint dwAssign, uint dwWhichMo
262265
return HRESULT.E_NOTIMPL;
263266
}
264267

265-
unsafe HRESULT IOleClientSite.Interface.GetContainer(IOleContainer** ppContainer)
268+
HRESULT IOleClientSite.Interface.GetContainer(IOleContainer** ppContainer)
266269
{
267270
if (ppContainer is null)
268271
{
@@ -273,7 +276,7 @@ unsafe HRESULT IOleClientSite.Interface.GetContainer(IOleContainer** ppContainer
273276
return HRESULT.S_OK;
274277
}
275278

276-
unsafe HRESULT IOleClientSite.Interface.ShowObject()
279+
HRESULT IOleClientSite.Interface.ShowObject()
277280
{
278281
if (_host.GetAxState(s_fOwnWindow))
279282
{

0 commit comments

Comments
 (0)