### Godot version

2992ffd25523cb8b3e0ef1b873c40115b8940178

### System information

Windows 10

### Issue description

Godot crashes randomly within a few seconds after project start when moving with the mouse.

![win_err](https://github.com/godotengine/godot/assets/52464204/1da28596-d95b-40f3-b32f-12219ec02c5d)

Started after recent merge of https://github.com/godotengine/godot/pull/67791.
I can confirm that reverting the pr fixes the crashes.

### Steps to reproduce

see desc

### Minimal reproduction project

N/A
KeySym keysym_unicode_nm = 0; 
		XLookupString(&xkeyevent_no_mod, nullptr, 0, &keysym_unicode_nm, nullptr);
		keysym = String::chr(xkb_keysym_to_utf32(xkb_keysym_to_upper(keysym_unicode_nm)));
	}
#endif
	
	if (!xmbstring) {
		
		xmbstring = (char *)memalloc(sizeof(char) * 8);
		xmblen = 8;
	}
	if (xkeyevent->type == KeyPress && wd.xic) {
		Status status;
#ifdef X_HAVE_UTF8_STRING
		int utf8len = 8;
		char *utf8string = (char *)memalloc(sizeof(char) * utf8len);
		int utf8bytes = Xutf8LookupString(wd.xic, xkeyevent, utf8string,
				utf8len - 1, &keysym_unicode, &status);
		if (status == XBufferOverflow) {
			utf8len = utf8bytes + 1;
			utf8string = (char *)memrealloc(utf8string, utf8len);
			utf8bytes = Xutf8LookupString(wd.xic, xkeyevent, utf8string,
					utf8len - 1, &keysym_unicode, &status);
		}
		utf8string[utf8bytes] = '\0';
		if (status == XLookupChars) {
			bool keypress = xkeyevent->type == KeyPress;
			Key keycode = KeyMappingX11::get_keycode(keysym_keycode);
			Key physical_keycode = KeyMappingX11::get_scancode(xkeyevent->keycode);
			if (keycode >= Key::A + 32 && keycode <= Key::Z + 32) {