Hey guys,

So I have this gui I created in Qt that embeds some X11 windows inside of it (and does a whole bunch of other stuff); when I close the application, I get a seg fault right after/ inside of the last destructor called.

It's entirely possible I missed something in one of the other portions of the gui, but due to the scarce Xlib documentation and the fact that I've been looking for the cause of the fault for a while now, I'm wondering if I'm misusing the Xlib functions.

All I'm doing is creating a few XWindows and displaying stuff in them using a third party library, like so (the following code is called a few times):

Display *display;
Screen *scr;
Window win;

display = XOpenDisplay (NULL);
scr = ScreenOfDisplay (display, DefaultScreen (display) );
win = XCreateSimpleWindow (display, DefaultRootWindow (display), 0, 0, 320, 240, 0, BlackPixel (display, DefaultScreen (display)), BlackPixel (display,  DefaultScreen (display)));
XMapWindow (display, win);
XFlush (display);

//displaying stuff in X windows

XDestroyWindow (display, win);
XCloseDisplay (display);
In particular, I couldn't find any good examples on closing them correctly; I'm not sure if XDestroyWindow() should be called before XCloseDisplay().