Fix memory leaks in GLib callback functions #205

Merged
jwharm merged 1 commit from glib-callback-memory-leaks into main 2025-04-12 12:12:00 +02:00
jwharm commented 2025-04-12 12:11:48 +02:00 (Migrated from github.com)

The GLib functions g_idle_add_once, g_timeout_add_once and g_timeout_add_seconds_once don't notify the caller when the callback function has finished. This causes a memory leak in Java-GI, because the arena in which the callback upcall stub was allocated, is never closed.

Because these three functions are simple wrappers around g_idle_add_full, g_timeout_add_full and g_timeout_add_seconds_full, which do notify the caller to free the callback allocation, they have been reimplemented in Java as custom wrappers that call the "full" functions and then return G_SOURCE_REMOVE.

The GLib functions `g_idle_add_once`, `g_timeout_add_once` and `g_timeout_add_seconds_once` don't notify the caller when the callback function has finished. This causes a memory leak in Java-GI, because the arena in which the callback upcall stub was allocated, is never closed. Because these three functions are simple wrappers around `g_idle_add_full`, `g_timeout_add_full` and `g_timeout_add_seconds_full`, which do notify the caller to free the callback allocation, they have been reimplemented in Java as custom wrappers that call the "full" functions and then return `G_SOURCE_REMOVE`.
Sign in to join this conversation.
No description provided.