From 64a7e75dd3066d838a68bcbe0fa54ebe60e23e47 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 5 Nov 2023 22:12:37 -0800 Subject: [PATCH] Only save ibus_addr_file after we've successfully read an address from it. Fixes https://github.com/libsdl-org/SDL/issues/3359 (cherry picked from commit bc3d9e99f381072820d29e75e6cc28fe40572c42) --- src/core/linux/SDL_ibus.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/linux/SDL_ibus.c b/src/core/linux/SDL_ibus.c index 4241cd4ad..a81ba1d4d 100644 --- a/src/core/linux/SDL_ibus.c +++ b/src/core/linux/SDL_ibus.c @@ -574,15 +574,17 @@ SDL_bool SDL_IBus_Init(void) return SDL_FALSE; } - /* !!! FIXME: if ibus_addr_file != NULL, this will overwrite it and leak (twice!) */ - ibus_addr_file = SDL_strdup(addr_file); - addr = IBus_ReadAddressFromFile(addr_file); if (addr == NULL) { SDL_free(addr_file); return SDL_FALSE; } + if (ibus_addr_file) { + SDL_free(ibus_addr_file); + } + ibus_addr_file = SDL_strdup(addr_file); + if (inotify_fd < 0) { inotify_fd = inotify_init(); fcntl(inotify_fd, F_SETFL, O_NONBLOCK);