nickguletskii / GLXOSD

GLXOSD is an extensible on-screen display (OSD)/overlay for OpenGL applications running on Linux with X11 which aims to provide similar functionality to MSI Afterburner/RivaTuner OSD. It can show FPS, frame timings, temperatures and more in OpenGL games and applications. It can also be used to benchmark games, much like voglperf.
https://glxosd.nickguletskii.com
MIT License
124 stars 20 forks source link

drawableHandlers not thread safe #47

Closed ghost closed 9 years ago

ghost commented 9 years ago

This is a theoretical issue that I haven't seen in practice, but still worth fixing?

In particular, this code:

void GLXOSD::osdHandleBufferSwap(Display* display, GLXDrawable drawable) {
...
    if (osdVisible && display && drawable) {

        auto it = drawableHandlers->find(glXGetCurrentContext());

        OSDInstance* instance;

        if (it == drawableHandlers->end()) {
            instance = new OSDInstance();
            drawableHandlers->insert(
                    std::pair(
                            glXGetCurrentContext(), instance));
        } else {
            instance = (*it).second;

glXSwapBuffers can be called from multiple threads at the same time, if they are using independent contexts. The use of drawableHandlers map isn't thread safe, inserting an element there while another thread is iterating (find) on the map will likely crash.

nickguletskii commented 9 years ago

Thank you. You are right, this issue must be fixed. It may also cause corruption in some cases.

nickguletskii commented 9 years ago

Should be fixed in 2.5.0.