diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-04-04 15:20:55 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-04-30 11:02:13 +0900 |
commit | 08a71c8f8d2d73bc1ba7d6b2a58b9ce30184c471 (patch) | |
tree | 31911b276cd39986fee04af0edc2a56c36b86379 /src/kernel/qeventloop_x11_glib.cpp | |
parent | f5bf794e23c940b8654f3f64ad62a0870cbf91c9 (diff) | |
download | tqt-08a71c8f8d2d73bc1ba7d6b2a58b9ce30184c471.tar.gz tqt-08a71c8f8d2d73bc1ba7d6b2a58b9ce30184c471.zip |
Correctly release glib mainloop and gsource, to avoid memory leaks
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'src/kernel/qeventloop_x11_glib.cpp')
-rw-r--r-- | src/kernel/qeventloop_x11_glib.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/kernel/qeventloop_x11_glib.cpp b/src/kernel/qeventloop_x11_glib.cpp index 4b44fe8f2..a13dbeebf 100644 --- a/src/kernel/qeventloop_x11_glib.cpp +++ b/src/kernel/qeventloop_x11_glib.cpp @@ -226,7 +226,7 @@ void TQEventLoop::init() printf("inside init(1)\n"); #endif - g_main_loop_new (d->ctx, 1); + d->mainloop = g_main_loop_new (d->ctx, 1); g_source_attach( (GSource*)qtGSource, d->ctx ); d->gSource = (GSource*)qtGSource; @@ -258,10 +258,22 @@ void TQEventLoop::cleanup() // cleanup the X11 parts of the event loop d->xfd = -1; + // stop polling the GSource + g_source_remove_poll(d->gSource, &d->threadPipe_gPollFD); + g_source_remove_poll(d->gSource, &d->x_gPollFD); + g_source_destroy(d->gSource); + + // unref the main loop + g_main_loop_unref(d->mainloop); + d->mainloop = nullptr; + + // unref the gsource + g_source_unref(d->gSource); + d->gSource = nullptr; + // unref the main context g_main_context_unref(d->ctx); - - // todo: destroy gsource + d->ctx = nullptr; } bool TQEventLoop::processEvents( ProcessEventsFlags flags ) |