Xlib provides functions that you can use to destroy a window or destroy all subwindows of a window.
To destroy a window and all of its subwindows, use XDestroyWindow().
To destroy all subwindows of a specified window, use XDestroySubWindows().