From 19005bb487c31aacecab333d8a40ab6434885911 Mon Sep 17 00:00:00 2001 From: Vincent Cheah Beng Keat Date: Fri, 24 Mar 2023 22:59:08 +0800 Subject: [PATCH 1/5] Fix valgrind leak reported on wayland Upstream-Status: Backport Expect it to be removed once move to v2023.2.0 and above. https://github.com/oneapi-src/oneVPL/commit/d276bb08e060956cde678d2c15fc291eec46d1dc --- .../legacy/sample_common/include/vaapi_utils.h | 2 ++ tools/legacy/sample_common/src/vaapi_device.cpp | 1 + tools/legacy/sample_common/src/vaapi_utils.cpp | 3 ++- .../sample_misc/wayland/src/class_wayland.cpp | 17 +++++++++++++++-- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tools/legacy/sample_common/include/vaapi_utils.h b/tools/legacy/sample_common/include/vaapi_utils.h index 9d80255..2598883 100644 --- a/tools/legacy/sample_common/include/vaapi_utils.h +++ b/tools/legacy/sample_common/include/vaapi_utils.h @@ -315,11 +315,13 @@ private: public: typedef Wayland* (*WaylandCreate_type)(void); + typedef void (*WaylandDestroy_type)(Wayland*); VA_WaylandClientProxy(); ~VA_WaylandClientProxy(); const WaylandCreate_type WaylandCreate; + const WaylandDestroy_type WaylandDestroy; }; #endif // LIBVA_WAYLAND_SUPPORT diff --git a/tools/legacy/sample_common/src/vaapi_device.cpp b/tools/legacy/sample_common/src/vaapi_device.cpp index e621251..98c5883 100644 --- a/tools/legacy/sample_common/src/vaapi_device.cpp +++ b/tools/legacy/sample_common/src/vaapi_device.cpp @@ -349,6 +349,7 @@ mfxStatus CVAAPIDeviceX11::RenderFrame(mfxFrameSurface1* pSurface, CVAAPIDeviceWayland::~CVAAPIDeviceWayland(void) { Close(); + m_WaylandClient.WaylandDestroy((MfxLoader::Wayland*)m_Wayland); } mfxStatus CVAAPIDeviceWayland::Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNum) { diff --git a/tools/legacy/sample_common/src/vaapi_utils.cpp b/tools/legacy/sample_common/src/vaapi_utils.cpp index e107624..d7aba0a 100644 --- a/tools/legacy/sample_common/src/vaapi_utils.cpp +++ b/tools/legacy/sample_common/src/vaapi_utils.cpp @@ -182,7 +182,8 @@ Xcbpresent_Proxy::~Xcbpresent_Proxy() {} VA_WaylandClientProxy::VA_WaylandClientProxy() : lib(WAYLAND_LIB), - SIMPLE_LOADER_FUNCTION(WaylandCreate) {} + SIMPLE_LOADER_FUNCTION(WaylandCreate), + SIMPLE_LOADER_FUNCTION(WaylandDestroy) {} VA_WaylandClientProxy::~VA_WaylandClientProxy() {} diff --git a/tools/legacy/sample_misc/wayland/src/class_wayland.cpp b/tools/legacy/sample_misc/wayland/src/class_wayland.cpp index 1a0bffa..8f6edbb 100644 --- a/tools/legacy/sample_misc/wayland/src/class_wayland.cpp +++ b/tools/legacy/sample_misc/wayland/src/class_wayland.cpp @@ -149,11 +149,15 @@ void Wayland::FreeSurface() { if (NULL != m_surface) wl_surface_destroy(m_surface); #if defined(WAYLAND_LINUX_XDG_SHELL_SUPPORT) - if (nullptr != m_xdg_toplevel) + if (NULL != m_xdg_toplevel) xdg_toplevel_destroy(m_xdg_toplevel); - if (nullptr != m_xdg_surface) + if (NULL != m_xdg_surface) xdg_surface_destroy(m_xdg_surface); #endif +#if defined(WAYLAND_LINUX_DMABUF_SUPPORT) + if (NULL != m_dmabuf) + zwp_linux_dmabuf_v1_destroy(m_dmabuf); +#endif } void Wayland::Sync() { @@ -379,10 +383,16 @@ struct wl_buffer* Wayland::CreatePrimeBuffer(uint32_t name, } Wayland::~Wayland() { +#if defined(WAYLAND_LINUX_XDG_SHELL_SUPPORT) + if (NULL != m_xdg_wm_base) + xdg_wm_base_destroy(m_xdg_wm_base); +#endif if (NULL != m_shell) wl_shell_destroy(m_shell); if (NULL != m_shm) wl_shm_destroy(m_shm); + if (NULL != m_drm) + wl_drm_destroy(m_drm); if (NULL != m_bufmgr) { drm_intel_bufmgr_destroy(m_bufmgr); } @@ -492,6 +502,9 @@ void Wayland::DestroyBufferList() { msdkFrameSurface* surface = FindUsedSurface(m_buffer->pInSurface); msdk_atomic_dec16(&(surface->render_lock)); } + wl_buffer_destroy(m_buffer->buffer); + m_buffer->buffer = NULL; + m_buffer->pInSurface = NULL; m_buffers_list.pop_front(); delete m_buffer; } -- 2.40.1