diff --git a/src/xrt/compositor/client/comp_egl_glue.c b/src/xrt/compositor/client/comp_egl_glue.c index d1556c291..e0c83f89d 100644 --- a/src/xrt/compositor/client/comp_egl_glue.c +++ b/src/xrt/compositor/client/comp_egl_glue.c @@ -31,7 +31,7 @@ client_egl_compositor_destroy(struct xrt_compositor *xc) { struct client_gl_compositor *c = client_gl_compositor(xc); // Pipe down call into fd compositor. - xrt_comp_destroy((struct xrt_compositor **)c->xcfd); + xrt_comp_fd_destroy(&c->xcfd); free(c); } diff --git a/src/xrt/compositor/client/comp_gl_xlib_client.c b/src/xrt/compositor/client/comp_gl_xlib_client.c index 378aea639..1734acd75 100644 --- a/src/xrt/compositor/client/comp_gl_xlib_client.c +++ b/src/xrt/compositor/client/comp_gl_xlib_client.c @@ -33,7 +33,7 @@ client_gl_xlib_compositor_destroy(struct xrt_compositor *xc) { struct client_gl_xlib_compositor *c = client_gl_xlib_compositor(xc); // Pipe down call into fd compositor. - xrt_comp_destroy((struct xrt_compositor **)c->base.xcfd); + xrt_comp_fd_destroy(&c->base.xcfd); free(c); } diff --git a/src/xrt/compositor/client/comp_vk_client.c b/src/xrt/compositor/client/comp_vk_client.c index a42e02d9f..c39b809ea 100644 --- a/src/xrt/compositor/client/comp_vk_client.c +++ b/src/xrt/compositor/client/comp_vk_client.c @@ -116,7 +116,7 @@ client_vk_compositor_destroy(struct xrt_compositor *xc) } // Pipe down call into fd compositor. - xrt_comp_destroy((struct xrt_compositor **)&c->xcfd); + xrt_comp_fd_destroy(&c->xcfd); free(c); } diff --git a/src/xrt/include/xrt/xrt_compositor.h b/src/xrt/include/xrt/xrt_compositor.h index ede5f7089..239b8ffef 100644 --- a/src/xrt/include/xrt/xrt_compositor.h +++ b/src/xrt/include/xrt/xrt_compositor.h @@ -777,6 +777,27 @@ xrt_comp_fd_create_swapchain(struct xrt_compositor_fd *xcfd, return (struct xrt_swapchain_fd *)xsc; } +/*! + * @copydoc xrt_compositor::destroy + * + * Helper for calling through the function pointer: does a null check and sets + * xcfd_ptr to null if freed. + * + * @public @memberof xrt_compositor_fd + */ +static inline void +xrt_comp_fd_destroy(struct xrt_compositor_fd **xcfd_ptr) +{ + struct xrt_compositor_fd *xcfd = *xcfd_ptr; + if (xcfd == NULL) { + return; + } + + xcfd->base.destroy(&xcfd->base); + *xcfd_ptr = NULL; +} + + #ifdef __cplusplus } #endif