When tweaking the debug logging for context in Keyman Engine for Linux (per #10365), I observed that g_autofree is probably being incorrectly used, resulting in a memory leak:
|
g_autofree gchar *debug_context = NULL; |
|
g_message("%s: before process key event: %s", __FUNCTION__, debug_context = get_context_debug(engine, NULL)); |
|
km_core_process_event(keyman->state, keycode_to_vk[keycode], km_mod_state, isKeyDown, KM_CORE_EVENT_FLAG_DEFAULT); |
|
g_message("%s: after process key event : %s", __FUNCTION__, debug_context = get_context_debug(engine, NULL)); |
According to the documentation g_autofree (aka __attribute__((cleanup))) only operates when the variable goes out of scope, not when it is reassigned. So the first assignment to debug_context above will be leaked. There is a 3rd use of the same variable in the function which means the second assignment will also be leaked.
When tweaking the debug logging for context in Keyman Engine for Linux (per #10365), I observed that
g_autofreeis probably being incorrectly used, resulting in a memory leak:keyman/linux/ibus-keyman/src/engine.c
Lines 937 to 940 in 9830f9e
According to the documentation
g_autofree(aka__attribute__((cleanup))) only operates when the variable goes out of scope, not when it is reassigned. So the first assignment todebug_contextabove will be leaked. There is a 3rd use of the same variable in the function which means the second assignment will also be leaked.