diff --git a/widget/gtk/WindowSurfaceProvider.cpp b/widget/gtk/WindowSurfaceProvider.cpp index faf147a80a4a1..b346f0783d101 100644 --- a/widget/gtk/WindowSurfaceProvider.cpp +++ b/widget/gtk/WindowSurfaceProvider.cpp @@ -52,6 +52,16 @@ WindowSurfaceProvider::WindowSurfaceProvider() { } +WindowSurfaceProvider::~WindowSurfaceProvider() { +#ifdef MOZ_WAYLAND + MOZ_DIAGNOSTIC_ASSERT(!mWidget, + "nsWindow reference is still live, we're leaking it!"); +#endif +#ifdef MOZ_X11 + MOZ_DIAGNOSTIC_ASSERT(!mXWindow, "mXWindow should be released on quit!"); +#endif +} + #ifdef MOZ_WAYLAND void WindowSurfaceProvider::Initialize(RefPtr aWidget) { mWindowSurfaceValid = false; diff --git a/widget/gtk/WindowSurfaceProvider.h b/widget/gtk/WindowSurfaceProvider.h index 353fa82f708fb..a040bbe3957f1 100644 --- a/widget/gtk/WindowSurfaceProvider.h +++ b/widget/gtk/WindowSurfaceProvider.h @@ -36,7 +36,7 @@ class GtkCompositorWidget; class WindowSurfaceProvider final { public: WindowSurfaceProvider(); - ~WindowSurfaceProvider() = default; + ~WindowSurfaceProvider(); /** * Initializes the WindowSurfaceProvider by giving it the window diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index 4e96f8218784a..fac9ea1cfef5b 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -615,6 +615,10 @@ void nsWindow::Destroy() { DestroyLayerManager(); + // mSurfaceProvider holds reference to this nsWindow so we need to explicitly + // clear it here to avoid nsWindow leak. + mSurfaceProvider.CleanupResources(); + g_signal_handlers_disconnect_by_data(gtk_settings_get_default(), this); if (mIMContext) {