From dddf67e07a4ec04fe6f1ee575ff58df2b7e056f5 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 13 Jul 2020 09:36:37 -0700 Subject: [PATCH] egl: add explicit drop impl for GlState This tidies up the valgrind output some more, but seems to highlight some leaks in the egl implementation around init/shutdown. I still don't see a smoking gun for a memory leak that grows over time. refs: https://github.com/wez/wezterm/issues/238 --- window/src/egl.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/window/src/egl.rs b/window/src/egl.rs index 46c96379e..3ad539448 100644 --- a/window/src/egl.rs +++ b/window/src/egl.rs @@ -50,6 +50,22 @@ pub struct GlState { context: ffi::types::EGLContext, } +impl Drop for GlState { + fn drop(&mut self) { + unsafe { + self.egl.egl.MakeCurrent( + self.display, + ffi::NO_SURFACE, + ffi::NO_SURFACE, + ffi::NO_CONTEXT, + ); + self.egl.egl.DestroySurface(self.display, self.surface); + self.egl.egl.DestroyContext(self.display, self.context); + self.egl.egl.Terminate(self.display); + } + } +} + type GetProcAddressFunc = unsafe extern "C" fn(*const std::os::raw::c_char) -> *const std::os::raw::c_void; @@ -67,7 +83,7 @@ impl EglWrapper { Ok(Self { _lib: lib, egl }) } - pub fn get_display( + fn get_display( &self, display: Option, ) -> anyhow::Result {