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.
This commit is contained in:
James Cowgill 2024-12-04 23:13:01 +00:00 committed by Lukas Dürrenberger
parent ad70442246
commit e1bb69b3b5

View File

@ -104,7 +104,12 @@ std::shared_ptr<_XIM> openXim()
XSetLocaleModifiers(""); XSetLocaleModifiers("");
// Create the input context // Create the input context
sharedXIM.reset(XOpenIM(UnixDisplayImpl::weakSharedDisplay.lock().get(), nullptr, nullptr, nullptr), XCloseIM); const auto closeIM = [](XIM im)
{
if (im)
XCloseIM(im);
};
sharedXIM.reset(XOpenIM(UnixDisplayImpl::weakSharedDisplay.lock().get(), nullptr, nullptr, nullptr), closeIM);
xim = sharedXIM; xim = sharedXIM;
// Restore the previous locale // Restore the previous locale