[client] overlay/msg: fix race condition in render
If an overlay is closed with overlayMsg_close, the message can be freed while it is still being used by msg_render, resulting in a segfault. Lock the message list for the duration of msg_render to fix this.
This commit is contained in:
1 parent
7e9e38faa5
commit
03ca20d3e4
3 files changed
+39
-25
No files matched your search
@@ -85,9 +85,14 @@ static bool msg_needsOverlay(void * udata)
|
||||
static int msg_render(void * udata, bool interactive, struct Rect * windowRects,
|
||||
int maxRects)
|
||||
{
|
||||
ll_lock(l_msg.messages);
|
||||
|
||||
struct Msg * msg;
|
||||
if (!ll_peek_head(l_msg.messages, (void **)&msg))
|
||||
if (!ll_peek_head_nl(l_msg.messages, (void **)&msg))
|
||||
{
|
||||
ll_unlock(l_msg.messages);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ImVec2 * screen = overlayGetScreenSize();
|
||||
igSetNextWindowBgAlpha(0.8f);
|
||||
@@ -163,7 +168,7 @@ static int msg_render(void * udata, bool interactive, struct Rect * windowRects,
|
||||
|
||||
if (destroy)
|
||||
{
|
||||
(void)ll_shift(l_msg.messages, NULL);
|
||||
(void)ll_shift_nl(l_msg.messages, NULL);
|
||||
freeMsg(msg);
|
||||
app_invalidateOverlay(false);
|
||||
}
|
||||
@@ -171,6 +176,7 @@ static int msg_render(void * udata, bool interactive, struct Rect * windowRects,
|
||||
overlayGetImGuiRect(windowRects);
|
||||
igEnd();
|
||||
|
||||
ll_unlock(l_msg.messages);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user