Skip to content

Null out host handle in OleInterfaces when disposing #13532

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

Merged
merged 1 commit into from
May 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private sealed unsafe class OleInterfaces :
IDisposable,
IManagedWrapper<IDispatch, IDispatchEx, IOleControlSite, IOleClientSite, IOleWindow, IOleInPlaceSite, ISimpleFrameSite, IVBGetControl, IGetVBAObject, IPropertyNotifySink>
{
private readonly AxHost _host;
private AxHost _host;
private ConnectionPointCookie? _connectionPoint;

internal OleInterfaces(AxHost host) => _host = host.OrThrowIfNull();
Expand All @@ -41,6 +41,9 @@ protected override void Dispose(bool disposing)
{
StopEvents();
}

// If we don't null this out, this will indirectly root the container control.
_host = null!;
}

internal AxHost GetAxHost() => _host;
Expand Down Expand Up @@ -251,7 +254,7 @@ HRESULT IOleControlSite.Interface.ShowPropertyFrame()
// IOleClientSite methods:
HRESULT IOleClientSite.Interface.SaveObject() => HRESULT.E_NOTIMPL;

unsafe HRESULT IOleClientSite.Interface.GetMoniker(uint dwAssign, uint dwWhichMoniker, IMoniker** ppmk)
HRESULT IOleClientSite.Interface.GetMoniker(uint dwAssign, uint dwWhichMoniker, IMoniker** ppmk)
{
if (ppmk is null)
{
Expand All @@ -262,7 +265,7 @@ unsafe HRESULT IOleClientSite.Interface.GetMoniker(uint dwAssign, uint dwWhichMo
return HRESULT.E_NOTIMPL;
}

unsafe HRESULT IOleClientSite.Interface.GetContainer(IOleContainer** ppContainer)
HRESULT IOleClientSite.Interface.GetContainer(IOleContainer** ppContainer)
{
if (ppContainer is null)
{
Expand All @@ -273,7 +276,7 @@ unsafe HRESULT IOleClientSite.Interface.GetContainer(IOleContainer** ppContainer
return HRESULT.S_OK;
}

unsafe HRESULT IOleClientSite.Interface.ShowObject()
HRESULT IOleClientSite.Interface.ShowObject()
{
if (_host.GetAxState(s_fOwnWindow))
{
Expand Down