Skip to content

Commit e1bb69b

Browse files
jcowgilleXpl0it3r
authored andcommitted
Fix segfault if XOpenIM fails
If `XOpenIM` fails we will store a `nullptr` into `sharedXIM`. When the shared `XIM` is destroyed we call the deleter `XCloseIM` on the `nullptr` which segfaults. Fix this by adding a new `closeIM` helper function which checks for null first.
1 parent ad70442 commit e1bb69b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/SFML/Window/Unix/Display.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ std::shared_ptr<_XIM> openXim()
104104
XSetLocaleModifiers("");
105105

106106
// Create the input context
107-
sharedXIM.reset(XOpenIM(UnixDisplayImpl::weakSharedDisplay.lock().get(), nullptr, nullptr, nullptr), XCloseIM);
107+
const auto closeIM = [](XIM im)
108+
{
109+
if (im)
110+
XCloseIM(im);
111+
};
112+
sharedXIM.reset(XOpenIM(UnixDisplayImpl::weakSharedDisplay.lock().get(), nullptr, nullptr, nullptr), closeIM);
108113
xim = sharedXIM;
109114

110115
// Restore the previous locale

0 commit comments

Comments
 (0)